r - 使用 rCharts hPlot 显示多个时间序列

标签 r highcharts shiny rcharts

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

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]]
)

最佳答案

尝试使用长格式数据 group :

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

关于r - 使用 rCharts hPlot 显示多个时间序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23534189/

相关文章:

使用 %b 格式化日期时出现 R strptime 问题

css - Highcharts/Highstock : Auto scroll on the graph with overflow-x, 而不是滚动条

javascript - Highcharts:在向下钻取之前获取一个事件?

r - R : How to include a colorbar, 中的 Plot_ly 符号和图例中标记的大小?

R Shiny 数据不可用 "Error: object not found"

javascript - 将 Javascript 对象转换为具有两个值的数组数组

r - 在 Shiny session 结束时保存用户输入?

r - 如何在 Shiny 上通过 downloadHandler 下载工作簿?

r - 在 Shiny 的应用程序和多个页面中进行身份验证

R:将记录插入矩阵时避免循环