1

This is exactly the same as this question, however instead of using Python, I am using R.

How do I avoid having 2 overlapping colorbar legends in plotly in R?

An example of this can be generated by

set.seed(123)

x = sample(1:ncol(volcano), size = 50)
y = sample(1:nrow(volcano), size = 50)
z = c()
for(i in 1:50) {z <- c(z, volcano[y[i], x[i]])}

df <- data.frame(x, y, z)

plot_ly(z = volcano, type = "surface") %>% 
add_trace(data = df, x = x, y = y, z = z, mode = "markers", type = "scatter3d", 
          marker = list(size = 5, symbol = 104, colorscale = "RdYlBu", autocolorscale = FALSE,
                        colorbar = list(xanchor = "left")), color = ~z,
          legendrank = 0)

Which produces

Example of overlapping colorbar legends

As can be seen by the code snippet neither using colorbar or legendrank are working, and both legends are plotted in the same location.

1 Answer 1

2

Worked it out straight after posting, but will keep it up as it is a useful question I think.

In the marker settings, you need to include colorbar = list(x=0)

1
  • 1
    for python users, you can do marker = dict(opacity=0.2, colorscale='Inferno', colorbar = dict(x=0))
    – Zahir
    Commented Dec 19, 2022 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.