This recipe teaches how to make marginal plots using plotly
. The way it's done is actually very similar to the way done with gridExtra
, that is, by drawing a grid and arranging the plots in it. An advantage of using plotly
is the interactivity that comes along with it. There is no need for supplemental packages; plotly
as a stand alone can do it.
- Use the
subplot()
function to arrange severalplotly
's plots into a single grid:
> library(plotly) > marg_plot <- subplot( plot_ly(data = iris, x = ~Petal.Length, type = 'histogram', color = ~Species, alpha =.5), plotly_empty(), plot_ly(data = iris, x = ~Petal.Length, y = ~Petal.Width, type = 'scatter', mode = 'markers', symbol = ~Species, color = ~Species, alpha = .5), plot_ly(data = iris, y = ~Petal.Width, type = 'histogram', color = ~Species, alpha = .5), nrows = 2, heights = c(.2, .8), widths = c(.8,.2), margin = 0, shareX ...