【问题标题】:Size Scale Disappears ggplotly大小比例消失 ggplotly
【发布时间】:2017-07-10 21:37:02
【问题描述】:

当我尝试使用 ggplotly() 时,我丢失了解释色阶的图例。如果我使用颜色而不是大小,则会出现图例。使用尺寸时如何让图例出现?

library(dplyr)
library(plotly)

plot <- mtcars %>%
  ggplot(aes(x = mpg, y = cyl, size = disp, frame = hp)) +
  geom_point()

ggplotly(plot) %>%
  layout(showlegend = T)

【问题讨论】:

    标签: r plotly


    【解决方案1】:

    我认为问题在于使用诸如 disp 之类的数字变量作为大小会创建一个非常大的图例,例如:

    p <- ggplot(data=mtcars, aes(x = mpg, y = cyl, colour=factor(disp), size = factor(disp))) +
    geom_point() 
    p <- ggplotly(p)
    p
    

    PS:我不确定您是否可以使用 frame 并仍然使用 ggplotly 获得所需的图例。

    选项2:直接使用plot_ly 例如:

    plot_ly(mtcars,x = ~ mpg, y= ~ cyl,  size = ~disp , type='scatter', mode = 'markers', frame = ~disp) %>%
    layout(showlegend = T)
    

    【讨论】:

    • 我认为 plot_ly 版本没有包含大小的图例。有一个带有样本点的图例,但没有向读者展示该样本点代表什么。我想要一个传说,就像我在我的问题中制作的“情节”ggplot 对象一样。
    • 由于该图是动态的,当您有大量数据点时,我不希望有静态图例。但是,该图在幻灯片右侧动态显示 disp 值。
    猜你喜欢
    • 2016-09-11
    • 2020-06-01
    • 1970-01-01
    • 2021-03-06
    • 2012-12-31
    • 2019-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多