0

I have the following code to generate a 3-D scatter plot:

IU_wide_2_filtered %>% 
  plot_ly(x = ~CI_scale, y = ~FI_scale, z = ~ConI_scale, type = "scatter3d", mode = "markers") %>%
  add_trace(x = ~CI_scale[clus_CI_FI_ConI == 1], y = ~FI_scale[clus_CI_FI_ConI == 1], z = ~ConI_scale[clus_CI_FI_ConI == 1], 
            type = "scatter3d", mode = "markers", 
            marker = list(size = 5, symbol = "circle", color = "#303030"),
            name = "Cluster 1") %>%
  add_trace(x = ~CI_scale[clus_CI_FI_ConI == 2], y = ~FI_scale[clus_CI_FI_ConI == 2], z = ~ConI_scale[clus_CI_FI_ConI == 2], 
            type = "scatter3d", mode = "markers", 
            marker = list(size = 5, symbol = "diamond", color = "#808080"),
            name = "Cluster 2") %>%
  add_trace(x = ~CI_scale[clus_CI_FI_ConI == 3], y = ~FI_scale[clus_CI_FI_ConI == 3], z = ~ConI_scale[clus_CI_FI_ConI == 3], 
            type = "scatter3d", mode = "markers", 
           marker = list(size = 5, symbol = "cross", color = "#000000"),
           name = "Cluster 3") %>%
  layout(scene = list(xaxis = list(title = "CI_scale"),
                      yaxis = list(title = "FI_scale"),
                      zaxis = list(title = "ConI_scale"),
                      showlegend = TRUE)) 

Which results in:

enter image description here

There's the "trace 0" legend entry, which should not be there. How do I remove it?

Adriaan
  • 17,741
  • 7
  • 42
  • 75
H B
  • 1
  • Could you please share some reproducible data using `dput`? – Quinten Mar 29 '23 at 13:19
  • Use showlegend = FALSE inside the trace. See also: https://plotly.com/r/legend/ – yaennu.s Mar 29 '23 at 14:12
  • Thank you very much for your advice! I was able to solve it as follows: IU_wide_2_filtered %>% plot_ly(x = ~CI_scale, y = ~FI_scale, z = ~ConI_scale, type = "scatter3d", mode = "markers", showlegend = FALSE) %>% add_trace(x = ~CI_scale[clus_CI_FI_ConI == 1], y = ~FI_scale[clus_CI_FI_ConI == 1], z = ~ConI_scale[clus_CI_FI_ConI == 1], type = "scatter3d", mode = "markers", marker = list(size = 5, symbol = "circle", color = "#303030"), name = "Cluster 1", showlegend = TRUE) %>% ... – H B Mar 29 '23 at 16:09
  • @HB Please post you solution as an answer and vote for it. Ty. – Alexander M. Mar 29 '23 at 21:48

0 Answers0