I want to use ggplot2 with grid.arrange to generate multiple plots with plotly. Some thing similar to this:
library(ggplot2)
library(gridExtra)
library(plotly)
g1<-ggplot(mpg, aes(displ, hwy, color=factor(year)))+geom_point()
g2<-ggplot(mpg, aes(cyl, hwy, color=factor(year)))+geom_point()
g<-grid.arrange(g1,g2,ncol=2)
ggplotly(g)
However, I am getting "Error in gg2list(p) : No layers in plot"
Any suggestions
Use the subplot function of plotly:
subplot(p1, p2, nrows = 2, margin = 0.04, heights = c(0.6, 0.4))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With