Configuring the alpha (opacity, transparency) for the items in legend of scatter plot of plotly

Viewed 519

I have data that has millions of rows and decided to plot it using Plotly in a 3 dimensional scatter plot. Since most of the points intersect with each other, I have decided to use an opacity value of 0.5. Naturally, the points in the legends become 50% opaque as well. However, I would like to have complete opaque points in the legend.

A sample that creates dummy data and shows the problem I've mentioned can be seen below.

library(dplyr)
library(plotly)

set.seed(77)

sample_data = data.frame(x = c(1:100), y = rnorm(100, mean = 1, sd = 0.5)) %>% 
  mutate(z = x*y,
         attr = if_else(x>50,"Big","Small"))

plot_ly() %>%
  add_trace(x = sample_data$x, 
            y = sample_data$y, 
            z = sample_data$z,
            color = sample_data$attr,
            colors = c("cyan4","orange"),
            type = "scatter3d",
            mode = "markers",
            opacity = 0.5,
            size = 1) %>%
  layout(legend = list(x = 0.5, 
                       y = 0.9,
                       bgcolor = "rgba(0,0,0,0)"))

The points located in the legend which is underlined in red are transparent as shown in sample output below.

plotly_sample

Finally, is there any way to set the alpha/opacity value of points in the legend of plotly, different from the points mapped inside the plot?

0 Answers
Related