1. library(rCharts)
  2. # year is converted to highcharts compatible datetime format
  3. huron <- data.frame(
  4. year = as.numeric(as.POSIXct(paste0(1875:1972, '-01-01')))*1000,
  5. level = as.vector(LakeHuron)
  6. )
  7. # add ymin and ymax to data
  8. dat <- transform(huron,
  9. ymin = level - 1,
  10. ymax = level + 1
  11. )
  12. # initialize highcharts object
  13. # add each layer as a series
  14. h1 <- Highcharts$new()
  15. h1$series(list(
  16. list(
  17. data = toJSONArray2(dat[,c('year', 'level')], names = F, json = F),
  18. zIndex = 1
  19. ),
  20. list(
  21. data = toJSONArray2(dat[,c('year', 'ymin', 'ymax')], names = F, json = F),
  22. type = 'arearange',
  23. fillOpacity = 0.3,
  24. lineWidth = 0,
  25. color = 'lightblue',
  26. zIndex = 0
  27. )
  28. ))
  29. h1$xAxis(type = 'datetime')
  30. h1