Plotly:多重美学的单一传奇
Plotly: single legend for multiple aesthetics
有没有办法在 Plotly 中使用单一图例实现多种美学?我使用 ggplot 绘制数周的数据,它变得非常嘈杂。因此,我同时使用颜色和形状来区分它们,而 ggplot 只是将它们组合在图例中。这是一个可重现的例子:
p<- ggplot(mtcars, aes(mpg,wt))+
geom_point(aes(color = factor(gear), shape = factor(gear)))+
geom_line(aes(color = factor(gear)))
p
此代码生成以下图:
现在,如果我使用
ggplotly(p)
我得到了下面的图,其中显示了两组图例。有什么方法可以使 Plotly 图例表现得像 ggplot 一样吗?
谢谢
我认为这可能仍然是 ggplot2 / plotly 的问题。或者,您可以尝试:
plot_ly(data = mtcars,
x= ~mpg, y = ~wt, color = ~factor(gear),
type = 'scatter', mode = 'lines+markers',
symbol = ~factor(gear),
symbols = c('circle','triangle-up','square'))
有没有办法在 Plotly 中使用单一图例实现多种美学?我使用 ggplot 绘制数周的数据,它变得非常嘈杂。因此,我同时使用颜色和形状来区分它们,而 ggplot 只是将它们组合在图例中。这是一个可重现的例子:
p<- ggplot(mtcars, aes(mpg,wt))+
geom_point(aes(color = factor(gear), shape = factor(gear)))+
geom_line(aes(color = factor(gear)))
p
此代码生成以下图:
现在,如果我使用
ggplotly(p)
我得到了下面的图,其中显示了两组图例。有什么方法可以使 Plotly 图例表现得像 ggplot 一样吗?
谢谢
我认为这可能仍然是 ggplot2 / plotly 的问题。或者,您可以尝试:
plot_ly(data = mtcars,
x= ~mpg, y = ~wt, color = ~factor(gear),
type = 'scatter', mode = 'lines+markers',
symbol = ~factor(gear),
symbols = c('circle','triangle-up','square'))