Plot multiple legends in R-plotly

旧巷老猫 提交于 2020-06-23 11:16:00

问题


I have 5 continuous variables that I'd like to graph together in R plotly.

I wrote the following code and got the plot to run as expected, but I cannot figure out how to deal with the legends. As is, the color legend appears, but the size legend does not.

I would like to plot both legends and control their locations within the plot. Suggestions from a similar post Adding color and bubble size legend in R plotly do not solve the problem.

Here's the code and sample data:

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

来源:https://stackoverflow.com/questions/62011571/plot-multiple-legends-in-r-plotly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!