当我尝试使用ggplotly()时,我丢失了解释颜色比例的图例。如果我使用颜色而不是大小,则会出现图例。如何在使用size时显示图例?
library(dplyr)
library(plotly)
plot <- mtcars %>%
ggplot(aes(x = mpg, y = cyl, size = disp, frame = hp)) +
geom_point()
ggplotly(plot) %>%
layout(showlegend = T)发布于 2017-07-11 06:27:55
我认为问题在于使用诸如disp之类的数值变量作为大小将创建一个非常大的图例,例如:
p <- ggplot(data=mtcars, aes(x = mpg, y = cyl, colour=factor(disp), size = factor(disp))) +
geom_point()
p <- ggplotly(p)
pPS:我不确定你能不能在使用ggplotly的时候还能使用frame和你想要的图例。
选项2:直接使用plot_ly,例如:
plot_ly(mtcars,x = ~ mpg, y= ~ cyl, size = ~disp , type='scatter', mode = 'markers', frame = ~disp) %>%
layout(showlegend = T)https://stackoverflow.com/questions/45022027
复制相似问题