通过rCharts格式化Highcharts图

时间:2013-08-17 09:35:06

标签: r highcharts rcharts

我在从rCharts工作中获得高图时遇到了一些麻烦。我的数据和预期的图形如下:

set.seed(123134)
y <- rnorm(20, 35, 4)
y[7] <- NA
y[13] <- NA
y <- rbind(t(t(y)), t(t(rep(NA, 10))))
fc <- rnorm(10, 35, 1)
fc <- rbind(t(t(rep(NA,20))), t(t(fc)))
uci <- rnorm(10, 38, 1)
uci <- rbind(t(t(rep(NA,20))), t(t(uci)))
lci <- rnorm(10, 32, 1)
lci <- rbind(t(t(rep(NA,20))), t(t(lci)))
plotData <- data.frame(y,fc,uci,lci)

h1 <- Highcharts$new()
h1$chart(type="line")
h1$series(data=plotData$y)
h1$series(data=plotData$fc)
h1$series(data=plotData$uci)
h1$series(data=plotData$lci)
h1$series(data=rep(30,30))
h1

主要是一些观察到的数据具有缺失值,预测和相应的间隔以及水平线显示的特定限制。现在,有一些我无法弄清楚的事情:

  1. 我希望预测和间隔具有相同的风格。如何将这三个系列的点样式更改为相同的样式?
  2. 水平线不必是交互式的。是否可以选择绘制简单的水平线?我没有使用http://docs.highcharts.com
  3. 的参考资料
  4. 如何从图例中删除某些系列?特别是我不希望区间包含在图例中。
  5. 有没有一种方法可以在观察到的数据中插入缺失值?或者我必须提前手动完成此操作吗?

1 个答案:

答案 0 :(得分:3)

嗨@ user2691669欢迎来到SO。我会尝试解决你的4个问题。

  1. 要设置样式,请使用带有选项符号= your style
  2. 的标记
  3. 要删除标记,请使用选项已启用= FALSE
  4. 的标记
  5. 要使用showInLegend = FALSE
  6. 在图例中没有系列节目
  7. 要插入缺失值,我可以提供的最好的是connectNulls = TRUE
  8. 您的代码可以编写为实现上述内容:

    set.seed(123134)
    y <- rnorm(20, 35, 4)
    y[7] <- NA
    y[13] <- NA
    y <- rbind(t(t(y)), t(t(rep(NA, 10))))
    fc <- rnorm(10, 35, 1)
    fc <- rbind(t(t(rep(NA,20))), t(t(fc)))
    uci <- rnorm(10, 38, 1)
    uci <- rbind(t(t(rep(NA,20))), t(t(uci)))
    lci <- rnorm(10, 32, 1)
    lci <- rbind(t(t(rep(NA,20))), t(t(lci)))
    plotData <- data.frame(y,fc,uci,lci)
    
    h1 <- Highcharts$new()
    h1$chart(type="line")
    h1$series(data=plotData$y, marker = list(symbol = 'circle'), connectNulls = TRUE)
    h1$series(data=plotData$fc, marker = list(symbol = 'circle'), connectNulls = TRUE)
    h1$series(data=plotData$uci, showInLegend = FALSE, marker = list(symbol = 'square'), connectNulls = TRUE)
    h1$series(data=plotData$lci, showInLegend = FALSE, marker = list(symbol = 'square'), connectNulls = TRUE)
    h1$series(data=rep(30,30), marker= list(enabled = FALSE))
    h1
    

    可在HighCharts api文档中查看各种选项。例如,标记选项位于this link

相关问题