简体   繁体   中英

Suppressing trace colors and legend in plotly's subplot

I'm producing a list of plotly figures in R :

set.seed(1)
scatter.list <- vector(mode="list",3)
require(plotly)

for(i in 1:3){
  df <- data.frame(x=rnorm(100),y=rnorm(100),a=LETTERS[sample(26,100,replace=T)])
  scatter.list[[i]] <- plot_ly(type='scatter',mode="markers",x=~df$x,y=~df$y,text=~df$a,data=df) %>%
    layout(xaxis=list(title=xlab,zeroline=F),yaxis=list(title=ylab,zeroline=F))
}

And then want to plot them using subplot :

plotly::subplot(scatter.list,nrows=3,titleX=T,titleY=T)

Which gives: 在此处输入图片说明

My question is how to have all points in all subplots in the same color and how to suppress the legend?

You can hide the legend with showlegend = FALSE and the set marker color manually via markers = list('color' = myColor))

在此处输入图片说明

require(plotly)
set.seed(1)
scatter.list <- vector(mode = "list", 3)
for(i in 1:3){
  df <- data.frame(x = rnorm(100),
                   y = rnorm(100),
                   a = LETTERS[sample(26, 100, replace = T)]
                   )
  scatter.list[[i]] <- plot_ly(type = 'scatter',
                               mode = 'markers',
                               x = ~df$x,
                               y = ~df$y,
                               text = ~df$a,
                               data= df, 
                               marker = list(color = 'darkred'), 
                               showlegend = FALSE) %>%
    layout(xaxis = list(title = xlab,
                        zeroline = F),
           yaxis = list(title = ylab,
                        zeroline = F))
}

plotly::subplot(scatter.list,
                nrows=3)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM