Search code examples
rggplot2facet-wrapggplotly

Empty charts added by ggplotly when using facet_wrap


Is there any way to remove the empty charts that are added to the last row when using facet_wrap with ggplotly?

I'm using facet_wrap to generate a plot like this:

library(ggplot2)
library(plotly)
g=ggplot(data=mtcars, aes(x=mpg, y=wt))+geom_point()+facet_wrap(~hp)
print(g)

That gives this figure:

ggplot version

If I try to use ggplotly, extra empty charts are added to the last row.

gg = ggplotly(g)
print(gg)

ggplotly version Is there any way to avoid this?


Solution

  • Installing the github version of both ggplot2 and plotly solves the issue.

    devtools::install_github("tidyverse/ggplot2")
    devtools::install_github("ropensci/plotly")
    
    library(ggplot2)
    library(plotly)
    
    g=ggplot(data=mtcars, aes(x=mpg, y=wt))+geom_point()+facet_wrap(~hp)
    print(g)
    
    gg = ggplotly(g)
    print(gg)