plotly.R icon indicating copy to clipboard operation
plotly.R copied to clipboard

Not all facets being shown with facet_wrap, boxplot and ggplotly

Open zross opened this issue 4 years ago • 1 comments

@cpsievert I'm seeing several open issues that are similar to this one (#1132, #1962, #1301, #1254, #1243, #1099, #1086, #897) and wasn't sure whether to add a new issue or not.

It seems like perhaps plotly is having some trouble with facet_wrap() -- my reprex is pretty simple. On my machine using the development (and non-development) version of plotly some facets are not being shown.

The images below are from plotly 4.9.4.9000.

library(ggplot2)
p <- ggplot(mtcars, aes(y = mpg)) + geom_boxplot() + facet_wrap(~cyl)
plotly::ggplotly(p)

Just ggplot2 (no plotly) image

ggplotly (missing a couple of boxes)

image

zross avatar Sep 28 '21 16:09 zross

The issue is that the box plots are placed at the wrong position, i.e. outside of the visible x axis range (You can see them by shifting the range using the slider):

image

Until this is fixed a workaround would be to explicitly map a constant on the x aes:

library(ggplot2)

p <- ggplot(mtcars, aes(x = 1, y = mpg)) +
  geom_boxplot() +
  facet_wrap(~cyl)

plotly::ggplotly(p)

Created on 2024-08-05 with reprex v2.1.0

trekonom avatar Aug 05 '24 07:08 trekonom