如何在绘图R图表中应用颜色变量

时间:2016-11-01 19:02:17

标签: r plotly

我有一个data.frame列,这是一种颜色,我希望将它应用于绘制图表中的行

library(plotly)
library(dplyr)

df <- tibble(team=c("A","A","A","A","B","B","B","B"),
         season=c(2000,2000,2001,2001,2000,2000,2001,2001),
         game=c(1,2,1,2,1,2,1,2),
         points=c(0,3,1,1,1,2,0,1),
         theColor=c("red","red","red","red","grey","grey","blue","blue"))

df %>%
  group_by(team,season) %>%
  plot_ly(x=~game,y=~points,color=~theColor) %>%
  add_lines() %>% 
  layout(showlegend=FALSE)

但这只会导致默认颜色

enter image description here

提前致谢

0 个答案:

没有答案