


Library ( plotly ) fig1 % layout ( annotations = list ( list ( x = 0.52, y = 1.05, text = "Third Subplot", showarrow = F, xref = 'paper', yref = 'paper' )) ) s 1 % layout ( annotations = list ( list ( x = 0.15, y = 1.2, text = "First Subplot", showarrow = F, xref = 'paper', yref = 'paper' ), list ( x = 0.85, y = 1.2, text = "Second Subplot", showarrow = F, xref = 'paper', yref = 'paper' )) ) fig % layout ( title = "Specs with Subplot Title", plot_bgcolor = '#e5ecf6', xaxis = list ( zerolinecolor = '#ffff', zerolinewidth = 2, gridcolor = 'ffff' ), yaxis = list ( zerolinecolor = '#ffff', zerolinewidth = 2, gridcolor = 'ffff' ), showlegend = FALSE, showlegend2 = FALSE, margin = 0.01 ) fig
SUBPLOT TITLE UPDATE
Library ( plotly ) #Initialize figures fig1 % layout ( xaxis = list ( title = 'xaxis1 title' ), yaxis = list ( title = 'yaxis1 title' )) fig2 % layout ( xaxis = list ( title = 'xaxis2 title', range = c ( 10, 50 )), yaxis = list ( title = 'yaxis2 title', range = c ( 40, 80 ))) fig3 % layout ( xaxis = list ( title = 'xaxis3 title', showgrid = FALSE ), yaxis = list ( title = 'yaxis3 title', showgrid = FALSE )) fig4 % layout ( xaxis = list ( title = 'xaxis4 title', type = 'log' ), yaxis = list ( title = 'yaxis4 title' )) #creating subplot fig % layout ( title = 'Customizing Subplot Axes', plot_bgcolor = '#e5ecf6', xaxis = list ( zerolinecolor = '#ffff', zerolinewidth = 2, gridcolor = 'ffff' ), yaxis = list ( zerolinecolor = '#ffff', zerolinewidth = 2, gridcolor = 'ffff' )) # Update title annotations = list ( list ( x = 0.2, y = 1.0, text = "Plot 1", xref = "paper", yref = "paper", xanchor = "center", yanchor = "bottom", showarrow = FALSE ), list ( x = 0.8, y = 1, text = "Plot 2", xref = "paper", yref = "paper", xanchor = "center", yanchor = "bottom", showarrow = FALSE ), list ( x = 0.2, y = 0.4, text = "Plot 3", xref = "paper", yref = "paper", xanchor = "center", yanchor = "bottom", showarrow = FALSE ), list ( x = 0.8, y = 0.4, text = "Plot 4", xref = "paper", yref = "paper", xanchor = "center", yanchor = "bottom", showarrow = FALSE )) fig % layout ( annotations = annotations ) fig Here is an example that creates a figure with a 2 x 2 subplot grid, populates each subplot with a scatter trace, and then updates the x and y axis titles for each subplot individually. The row and col arguments can be used to control which axes are targeted by the update. By default, these methods apply to all of the x axes or y axes in the figure.


Customizing Subplot AxesĪfter a figure with subplots is created using the subplot function, its axis properties (title, font, range, grid style, etc.) can be customized using the xaxis and yaxis graph object figure methods. Library ( dash ) library ( dashCoreComponents ) library ( dashHtmlComponents ) library ( plotly ) app <- Dash $ new () app $ layout ( htmlDiv ( list ( dccGraph ( id = 'graph-with-slider' ), htmlLabel ( 'Subplots Width:' ), dccSlider ( id = 'slider', min = 0, max = 1, value = 0.5, step = 0.01 ) ) ) ) app $ callback ( output ( id = 'graph-with-slider', property = 'figure' ), params = list ( input ( id = 'slider', property = 'value' )), function ( value ) )Īfter executing this code, give app$run_server() in the console to start the dash. Library ( plotly ) fig1 % layout ( title = 'Multiple Subplots with Titles', plot_bgcolor = '#e5ecf6', xaxis = list ( zerolinecolor = '#ffff', zerolinewidth = 2, gridcolor = 'ffff' ), yaxis = list ( zerolinecolor = '#ffff', zerolinewidth = 2, gridcolor = 'ffff' )) annotations = list ( list ( x = 0.2, y = 1.0, text = "Plot 1", xref = "paper", yref = "paper", xanchor = "center", yanchor = "bottom", showarrow = FALSE ), list ( x = 0.8, y = 1, text = "Plot 2", xref = "paper", yref = "paper", xanchor = "center", yanchor = "bottom", showarrow = FALSE ), list ( x = 0.2, y = 0.45, text = "Plot 3", xref = "paper", yref = "paper", xanchor = "center", yanchor = "bottom", showarrow = FALSE ), list ( x = 0.8, y = 0.45, text = "Plot 4", xref = "paper", yref = "paper", xanchor = "center", yanchor = "bottom", showarrow = FALSE )) fig % layout ( annotations = annotations ) #options(warn = -1) fig
