Black Lives Matter. Please consider donating to Black Girls Code today.

Using subplot shifts grouped boxplot to a side

Hello,

I am trying to plot multiple grouped box plots using subplots in Plotly.

When I tried to do this, each plotly object that is passed to subplot function will display the plots shifted to the side.

For example,

p <- plot_ly(ggplot2::diamonds, x = ~cut, y = ~price, color = ~clarity, type = “box”) %>%
layout(boxmode = “group”)
q <- plot_ly(ggplot2::diamonds, x = ~cut, y = ~price, color = ~clarity, type = “box”) %>%
layout(boxmode = “group”)
s1 <- subplot(p, q, nrows = 2)
s1

The plot s1 will look like,

All the plots at top row is shifted to left and the plots at the bottom is shifted to the right from the center of axis tick.

Is there a way to prevent this shift and center all the plots?

1 Like

I found this problem as well. Hope we could get some help.

Anybody have any luck with this?