I have a time series of several years that I need to plot mm/dd on the x-axis and multiple years on the y-axis using plot_ly. I have generated a sample data here:
date<-seq(as.Date("2010-11-22"),as.Date("2016-05-26"),by ="days")
sales = runif(2013, 2000, 6000)
df = data.frame(date,sales)
I plotted this data and get this:
plot_ly(df,x= ~date) %>% add_lines(y = ~sales,color=I("red"))
Now, I tried to plot multiple y-axis using plot_ly
:
plot_ly(df, x = ~date) %>% add_lines(y = ~sales,
df$date <= "2010-12-31",color=I("red")) %>%
add_lines(y = ~sales, df$date <= "2013-12-31" &
df$date >= 2013-01-01, color = I("green"))
but I got wrong plot:
What's the mistake in that?
I want the plot like this: