Highcharts区域范围在rCharts中绘制 [英] Highcharts Area Range Plot in rCharts
问题描述
有谁知道是否可以在rCharts中创建一个区域范围样式图( http:// www.highcharts.com/demo/arearange-line )?
does anyone know if it's possible to create a area range style plot in rCharts (http://www.highcharts.com/demo/arearange-line)?
我的基本问题是简单预测场景的可视化:
My basic problem is the visualisation of a simple forecast scenario:
set.seed(123134)
y <- c(rnorm(20, 35, 2), rep(NA, 10))
data <- data.frame(y=y)
data$fc <- c(rep(NA, 20), rnorm(10, 35, 1))
data$lci <- data$fc-1
data$uci <- data$fc+1
h1 <- Highcharts$new()
h1$chart(type="line")
h1$series(data=data$y, marker = list(symbol = 'circle'), connectNulls = TRUE)
h1$series(data=data$fc, marker = list(symbol = 'circle'), connectNulls = TRUE)
h1$series(data=data$uci, showInLegend = FALSE, marker = list(symbol = 'square'), connectNulls = TRUE)
h1$series(data=data$lci, showInLegend = FALSE, marker = list(symbol = 'square'), connectNulls = TRUE)
h1$series(data=rep(30,30), marker= list(enabled = FALSE))
h1
谢谢!
Thanks!
推荐答案
这是区域范围图示例。
Here is an example of an area range chart. I am adding the code below as well.
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
编辑。输入系列的简单方法是使用系列
方法并分别添加两个数据系列。
EDIT. A simpler way to input series is to use the series
method and add the two data series separately. This avoids the nested list, which can get ugly.
h1 <- Highcharts$new()
h1$series(
data = toJSONArray2(dat[,c('year', 'level')], names = F, json = F),
zIndex = 1,
name = "Level"
)
h1$series(
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
编辑2:如高位图中的范围描述,您可以添加以下代码行。请注意,集合
方法可用于为图表添加任意任意键值对。
To add a range description as in the highcharts chart, you can add the following line of code. Note that the set
method can be used to add any arbitrary key-value pair for a chart.
h1$set(tooltip = list(
crosshairs = T,
shared = T,
valueSuffix = '°C'
))
这篇关于Highcharts区域范围在rCharts中绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!