In a previous post I asked about how to change the colors of point outlines in R plotly 3d scatter plots:
The problem with the best solution I found is that the colors of the point outlines don’t appear in the legend because we are using colors lined up with the categorical variable of interest rather than an automatic mapping. This code illustrates the problem (note the legend for the main point color, but no information about the outline):
library(plotly) roots <- round(runif(n = dim(iris),min = -.499,max = 2.499)) roots_colors <- vector(mode="character", length=length(roots)) #setting the value of roots colors to be the colors we want roots_colors[roots == 0] <- "#000000ff" roots_colors[roots == 1] <- "#ff0000ff" roots_colors[roots == 2] <- "#0000ffff" my_iris <- cbind(data.frame(roots_colors), iris, data.frame(as.character(roots))) plot_ly() %>% add_trace(data = my_iris, type = 'scatter3d', mode = "markers", x = ~Sepal.Length, y = ~Petal.Length, z = ~Sepal.Width, color = ~Species, colors = c("#00ffff34","#ffff00dd","#ff00ff11"), marker = list( line = list( color = ~roots_colors, width = 3 ) ) )
Is there any way to make the legend include entries that reflect the outline of the markers?