Search code examples
rplotrcharts

R rCharts - a slider not appearing when x-axis values are the dates


I am building a rCharts object. It uses a vector of strings formatted like a data ("yyyy-mm-dd") as values of x-axis. This way is taken from this rCharts 'official' tutorial (find m1 plot code) - in both (tutorial's and mine) cases the x-axis values are of character type and rCharts seems to recognize it (for example it sets the x-axis visible values to "yyyy-mm" format when the scope is narrow enough etc.)

For my purposes, it would be absolutely great if I could use the slider in the x-axis, but my implementation fails to work... The slider simply does not appear at all. Below is a short R code with such not-working-with-slider plot. Any solutions?

library(rCharts)

set.seed(101)

dates <- c("1959-01-01", "1959-02-01", "1959-03-01", "1959-04-01", "1959-05-01", "1959-06-01",
       "1959-07-01", "1959-08-01", "1959-09-01", "1959-10-01", "1959-11-01", "1959-12-01",
       "1960-01-01", "1960-02-01", "1960-03-01", "1960-04-01", "1960-05-01", "1960-06-01",
       "1960-07-01", "1960-08-01", "1960-09-01", "1960-10-01", "1960-11-01", "1960-12-01")
data1 <- rnorm(n=24, m=1, sd=1) 
data2 <- rnorm(n=24, m=0, sd=2) 
df <- data.frame(dates, data1, data2)

plot <- mPlot(x = "dates", y = c("data1", "data2"), type = "Line", data = df)
plot$set(slider=TRUE)
plot

Solution

  • Posting my comment as an answer. mPlot uses the MorrisJS library, which does not have native support for sliders built in. If you look at the examples, you will notice that the slider method is supported by the JS library Rickshaw.