I have the following sample dataframe and I'm using Plotly in my R Shiny app to create a multi line plot:
df2=data.frame(DATE=as.Date(c('2022-01-04','2022-01-08','2022-02-06','2022-01-12','2022-02-15','2022-01-25','2022-02-08')),
QUANTITY=c(50,50,50,120,120,70,50),
PRICE=c(111,112, 104,90,93,98,105), TYPE=c('summer','summer','summer','summer','summer','winter','winter'),
COLOR=c('blue','blue','blue','blue','blue','red','red'))
plot_ly(df2, x = ~eval(parse(text='DATE')),
y = ~eval(parse(text='PRICE')), color = ~eval(parse(text='COLOR')), connectgaps = TRUE) %>% add_lines()
The three questions I have are the following:
- why the color doesn't work? I'm getting lines that are blue and green.
- I would need to use column 'QUANTITY' to determine the thickness of the lines. For example, one line should be given by quantity = 50 and color = blue and a different line (thicker) by quantity = 120 and color = blue.
- Is it possible to have for example one line being line+markers and another line being only markers and pass this info as a column of the dataframe? Thanks.


