Hello everyone,
I started using plotly for R recently and I’m stuck with a problem I can’t solve on my own :
I’m trying to draw a scatter plot for a time serie with a color which depend on some exogenous variable.
But once I add the color option in my code, the plot is rendered from 1970 instead of the data starting date.
I have no idea if it’s a bug or something wrong with my code.
Here’s a simple example to reproduce my problem :
dtime ← c(“2014-01-01”,“2015-01-01”,“2016-01-01”,“2017-01-01”) %>% ymd
dvalues ← rep(0,4)
dcolor ← c(0,0,1,1)
data_test ← data.frame(dtime,dvalues,dcolor)
pal ← c(“red”, “blue”, “green”)#no color : x-range is ok
plot_ly(data_test, x = ~dtime) %>%
add_trace(y = ~dvalues, name = “test”,type=“scatter”,mode=“markers”) %>%
layout(
title = “Plotly test”,
xaxis = list(rangeslider = list(type = “date”)),
yaxis = list(title = “values”))#with colors : x-range doesn’t work correctly
plot_ly(data_test, x = ~dtime) %>%
add_trace(y = ~dvalues, name = “test”,type=“scatter”,color=~dcolor,colors=pal,mode=“markers”) %>%
layout(
title = “Plotly test”,
xaxis = list(rangeslider = list(type = “date”)),
yaxis = list(title = “values”))#with colors and manual range
plot_ly(data_test, x = ~dtime) %>%
add_trace(y = ~dvalues, name = “test”,type=“scatter”,color=~dcolor,colors=pal,mode=“markers”) %>%
layout(
title = “Plotly test”,
xaxis = list(rangeslider = list(type = “date”),range=c(“2014-01-01”,“2017-01-01”)),
yaxis = list(title = “values”))