2017-04-04 61 views
0

我生产的plotly图列表中R抑制跟踪的色彩和传奇plotly的插曲

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)) 
} 

,然后想用subplot绘制它们:

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

其中给出: enter image description here

我的问题是如何在所有的次要情节的所有点相同颜色的ð如何抑制传奇?

回答

2

您可以隐藏与showlegend = FALSE传说和手动设定标记颜色通过markers = list('color' = myColor))

enter image description here

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)