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
As can be seen by the code snippet neither using colorbar
or legendrank
are working, and both legends are plotted in the same location.