library(rCharts)
# year is converted to highcharts compatible datetime format
huron <- data.frame(
year = as.numeric(as.POSIXct(paste0(1875:1972, '-01-01')))*1000,
level = as.vector(LakeHuron)
)
# add ymin and ymax to data
dat <- transform(huron,
ymin = level - 1,
ymax = level + 1
)
# initialize highcharts object
# add each layer as a series
h1 <- Highcharts$new()
h1$series(list(
list(
data = toJSONArray2(dat[,c('year', 'level')], names = F, json = F),
zIndex = 1
),
list(
data = toJSONArray2(dat[,c('year', 'ymin', 'ymax')], names = F, json = F),
type = 'arearange',
fillOpacity = 0.3,
lineWidth = 0,
color = 'lightblue',
zIndex = 0
)
))
h1$xAxis(type = 'datetime')
h1