【问题标题】:Display multiple time series with rCharts hPlot使用 rCharts hPlot 显示多个时间序列
【发布时间】:2014-05-08 06:21:31
【问题描述】:

用一个简单的数据框来说明这个问题:

df <- data.frame(x=c(1,2,3), y1=c(1,2,3), y2=c(3,4,5))

单时间序列图很简单:

hPlot(y="y1", x="x", data=df)

无法弄清楚如何将 y1 和 y2 绘制在一起。试过这个,但它返回一个错误

> hPlot(x='x', y=c('y1','y2'), data=df)

Error in .subset2(x, i, exact = exact) : subscript out of bounds

检查 hPlot 中的代码,它使用 [[ 从输入 data.frame 中提取一列,这是否意味着它仅适用于单个时间序列?

hPlot <- highchartPlot <- function(..., radius = 3, title = NULL, subtitle = NULL, group.na = NULL){
rChart <- Highcharts$new()

# Get layers
d <- getLayer(...)

data <- data.frame(
    x = d$data[[d$x]],
    y = d$data[[d$y]]
)

【问题讨论】:

    标签: r highcharts shiny rcharts


    【解决方案1】:

    尝试使用带有group的长格式数据:

    hPlot(x = "x", y = "value", group = "variable", data = reshape2::melt(df, id.vars = "x"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-15
      • 2021-11-12
      相关资源
      最近更新 更多