2015-12-28 40 views
1

我想添加交互作用到我的情節圖的填充參數,例如,回答了here填充交互不與ggplot2一起工作,並積極

但是,雖然ggplot數字出來正確,情節並沒有。我使用的是以下版本,並顯示以下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以上不同的任何想法?

回答

2

不是一個完整的解決方案。包括交互x term:

# 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) 
+0

完美的作品謝謝! – Nick

+0

任何想法修復[這](http://stackoverflow.com/questions/34493789/how-to-change-the-position-of-plotly-figures-using-ggplotly)問題? – Nick

1

實際上有一個替代方案,會給你你想要的東西。

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") 

enter image description here