ggplot 到 ggplotly 不适用于自定义 geom_boxplot 宽度

ggplot to ggplotly doesn't work with customized geom_boxplot width

当我尝试在 ggplot 中为我的箱线图设置自定义宽度时,它工作正常:

p=ggplot(iris, aes(x = Species,y=Sepal.Length )) + geom_boxplot(width=0.1)

但是当我尝试使用 ggplotly 时,宽度(和 hjust)是默认值:

p %>% ggplotly()

我做错了什么或者这是 ggplotly 中的错误?

您可以使用布局来设置 boxgap:

library(ggplot2)
library(plotly)

p <- ggplot(iris, aes(x = Species,y=Sepal.Length )) +
   geom_boxplot()

ggplotly(p) %>% plotly::layout(boxgap=0.9)

另见 https://plot.ly/python/box-plots/#Grouped-Box-Plot