在R-plotly中绘制多个图例

时间:2020-05-25 22:13:03

标签: r plotly r-plotly

我有5个连续的变量,希望在R中以图形方式一起绘制。

我编写了以下代码,使图可以按预期运行,但是我无法弄清楚如何处理图例。按原样显示颜色图例,但不显示尺寸图例。

我想绘制两个图例并控制它们在图中的位置。来自类似帖子Adding color and bubble size legend in R plotly的建议不能解决问题。

这是代码和示例数据:

x<-sample(30)
y<-sample(30)
z<-sample(30)
c<-sample(30)
s<-sample(30)

fig <- plot_ly (x = x, y = y, z = z, color = c, 
                colors = c("#440154FF", "#1F968BFF", "#FDE725FF"), size = s,
                marker = list(symbol = 'circle', sizemode = 'diameter'), sizes = c(1, 30))

fig <- fig %>% add_markers()

fig <- fig %>% layout(scene = list(xaxis = list (title = 'X'),
                      yaxis = list(title = 'Y'),
                      zaxis = list(title = 'Z'),
                      annotations = list(x = 1.05, y =1.02,
                                         text = 'Gradient title',
                                         xref = 'paper', yref = 'paper',
                                         showarrow=FALSE, showlegend=TRUE)))

fig

0 个答案:

没有答案