Display multiple time series with rCharts hPlot

Using a simple data frame to illustrate this problem:

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

The single time series chart is simple:

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

It is impossible to figure out how to group both y1 and y2 together. Tried this, but it returns an error

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

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

Checking the code in hPlot, where it uses [[to extract a single column from input data.frame, does this mean that it works only for individual time series?

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]]
)
+4
source share
1 answer

Try using long formatted data with group:

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

Source: https://habr.com/ru/post/1539705/


All Articles