Reputation: 6314
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)
My question is how to have all points in all subplots in the same color and how to suppress the legend?
Upvotes: 0
Views: 3303
Reputation: 31679
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)
Upvotes: 2