【问题标题】:fill Interaction not working with ggplot2 and plotly填充交互不适用于ggplot2和plotly
【发布时间】:2016-04-02 03:16:43
【问题描述】:

我想为我的 plotly 图形的 fill 参数添加交互,例如回复here

然而,虽然 ggplot 数字正确显示,但 plotly 却没有。我正在使用以下版本并在下面显示 MWE:

ggplot2:版本2.0.0.9000plotly:版本2.0.19

library(plotly)
g <- ggplot(mtcars, aes(x = factor(cyl), y = mpg, fill = interaction(factor(cyl),carb))) + geom_boxplot()
(gg <- ggplotly(g))

任何想法为什么 g 和 gg 在上面不同?

【问题讨论】:

    标签: r ggplot2 plotly


    【解决方案1】:

    不是一个完整的解决方案。将交互添加到您的 x 术语中:

    # use lex.order to obtain correct ordered levels
    a <- ggplot(mtcars, aes(x = interaction(cyl, carb, lex.order = T), y = mpg,fill = interaction(cyl, carb, lex.order = T))) + 
         geom_boxplot()
    # check the plot
    a
    # plotly
    ggplotly(a)
    

    【讨论】:

    • 关于解决this问题的任何想法?
    【解决方案2】:

    实际上有一个替代方案可以为您提供您想要的。

    mtcars$intec <- interaction(factor(cyl),carb)
    
    mtcars %>%
      plot_ly(x = cyl, y = mpg, type = "box", color = as.factor(intec), fill=as.factor(intec)) %>%
      layout(boxmode = "group")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-19
      • 1970-01-01
      • 2014-06-08
      • 1970-01-01
      • 2017-04-21
      • 2017-02-01
      • 2014-10-24
      • 2020-07-23
      相关资源
      最近更新 更多