【问题标题】:Problems with legend in conversion from ggplot to plotly从 ggplot 转换为 plotly 的图例问题
【发布时间】:2016-04-14 08:30:24
【问题描述】:

我对 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 中,我看不到我的任何更改。

非常感谢!

【问题讨论】:

标签: r ggplot2 plotly


【解决方案1】:

正如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))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-16
    • 2021-03-17
    • 2021-07-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多