从ggplot到plotly的转换中的图例问题

时间:2016-04-14 08:30:24

标签: r ggplot2 plotly

我在ggplotly中遇到传奇问题。这就是我的意思:

library(reshape2) # for melt 
df <- melt(outer(1:4, 1:4), varnames = c("X1", "X2"))
    p1 <- ggplot(df, aes(X1, X2)) + geom_tile(aes(fill = value))
    p2 <- p1 + guides(fill = guide_legend(title = "LEFT", title.position = "left")) p2
    ggplotly(p2)

我制作了更复杂的ggplot,并且我的传奇很多。在ggplotly中,我看不到任何变化。

非常感谢!

1 个答案:

答案 0 :(得分:0)

正如MLavoie所述,您可以尝试扩展边距(https://plot.ly/r/reference/#layout-margin):

library(reshape2) # for melt 
df <- melt(outer(1:4, 1:4), varnames = c("X1", "X2")) 
p1 <- ggplot(df, aes(X1, X2)) + geom_tile(aes(fill = value))
p2 <- p1 + guides(fill = guide_legend(title = "LEFT", title.position = "left")) 
ggplotly(p2) %>% layout(margin=list(r=120))