Ant*_*ony 4 r highcharts shiny rcharts
使用简单的数据框来说明此问题:
df <- data.frame(x=c(1,2,3), y1=c(1,2,3), y2=c(3,4,5))
Run Code Online (Sandbox Code Playgroud)
单时间序列图很容易:
hPlot(y="y1", x="x", data=df)
Run Code Online (Sandbox Code Playgroud)
无法弄清楚如何同时绘制y1和y2.试过这个,但它返回一个错误
> hPlot(x='x', y=c('y1','y2'), data=df)
Run Code Online (Sandbox Code Playgroud)
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]]
)
Run Code Online (Sandbox Code Playgroud)
尝试使用长格式数据group:
hPlot(x = "x", y = "value", group = "variable", data = reshape2::melt(df, id.vars = "x"))
Run Code Online (Sandbox Code Playgroud)