r - Plotly:单一传奇,多重美学

标签 r ggplot2 plotly legend-properties r-plotly

有没有办法在 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

此代码生成以下图: enter image description here

现在,如果我使用

ggplotly(p)

我得到以下图,其中显示两组图例。有没有办法让 Plotly 图例像 ggplot 一样?

enter image description here

谢谢

最佳答案

我认为这可能仍然是 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'))  

关于r - Plotly:单一传奇,多重美学,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48728295/

相关文章:

r - R 中的在线机器学习

r - 如何创建要插入到 ggplot 中的对象(当有多个带 + 的部分时)?

r - x轴值为日期时的困难注释图

python - 如何在X轴上添加水平滚动条?

r - 如何使用模式使用通配符组合数据帧?

python - 简单数据操作 : R vs python

python - plotly sankey 图数据格式

python - 更新散点图的最快方法是什么?

ide - R 中的命令历史记录

r - ggplot2 facet_wrap 与数学表达式