【问题标题】:Formatting Highcharts plot via rCharts通过 rCharts 格式化 Highcharts 绘图
【发布时间】:2013-08-17 09:35:05
【问题描述】:

我在从 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. 有没有办法在观察到的数据中插入缺失值?还是我必须提前手动执行此操作?

【问题讨论】:

    标签: r highcharts rcharts


    【解决方案1】:

    您好@user2691669 欢迎来到 SO。我将尝试解决您的 4 个问题。

    1. 要设置样式,请使用带有选项符号的标记 = your style
    2. 要删除标记,请使用启用选项的标记 = FALSE
    3. 要在传说中没有系列节目,请使用showInLegend = FALSE
    4. 要插入缺失值,我能提供的最好方法是connectNulls = TRUE

    你的代码可以写成:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多