0

I have a column of a data.frame which is a color and am looking to apply this to lines in a plotly chart

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)

But this just results in default colors

enter image description here

Thanks in advance

pssguy
  • 3,455
  • 7
  • 38
  • 68
  • I presume you were looking to change the palette. This could potentially help http://moderndata.plot.ly/create-colorful-graphs-in-r-with-rcolorbrewer-and-plotly/ – ArunK Nov 01 '16 at 21:00
  • @theArun Thanks. i have used that useful resource. i'm just wanting to have colors on chart reflect the 'theColor' variable. pretty sure i had achieved that in earlier version of plotly R package – pssguy Nov 01 '16 at 21:14
  • Makes better sense now.. this particular SO question resembles your requirement http://stackoverflow.com/questions/35601464/custom-colors-in-plotly – ArunK Nov 01 '16 at 21:19

0 Answers0