Black Lives Matter. Please consider donating to Black Girls Code today.

Plotly subplot legend

Hello all,

I would like to use subplot and show plots that are generated in a loop as a list. But I want to have only one legend. The solution I found so far, is using “showlegend = FALSE” for each plot or using " %>% layout(showlegend=F)" for the subplot, which non of them works for me. Because I generate the plots in the loop as list and pass the list as one argument into subplot.

subplot(plots, shareX = TRUE, titleX=T, titleY = TRUE)

where plots is generated as:
plots <- list()

for(nm in 1:Given_Input) {
df.plot = data.frame(as.factor(df.subset$User.ID),df.subset$Date,df.subset[,colno])
colnames(df.plot) = c(“ID”, “Variable”,“Value”)

plots[[nm]] <- ggplot(df.plot , aes(Variable, Value , group= ID )) +geom_line(aes(color=ID)) + geom_point(aes(color=ID)) +
theme(axis.text.x = element_text(face=“bold”, color="#993333", size=8)) +
ylab(scorename) + xlab(“Date”) + ggtitle(“Whoop data” ) + theme(axis.text.x=element_text(angle=90,hjust=1)) + theme(legend.title=element_blank())


Does anyone has a solution for that? Thank you for your time and help in advance.