【问题标题】:ggplot to ggplotly doesn't work with customized geom_boxplot widthggplot 到 ggplotly 不适用于自定义 geom_boxplot 宽度
【发布时间】:2020-01-23 19:55:32
【问题描述】:

当我尝试在 ggplot 中为我的箱线图设置自定义宽度时,效果很好:

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

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

p %>% ggplotly()

我做错了什么还是 ggplotly 中的错误?

【问题讨论】:

    标签: r ggplot2 plotly boxplot ggplotly


    【解决方案1】:

    你可以使用layout来设置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

    【讨论】:

      猜你喜欢
      • 2011-07-27
      • 1970-01-01
      • 2013-07-07
      • 2020-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-20
      • 2015-08-30
      相关资源
      最近更新 更多