Question

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

Single time series plot is easy:

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

Cannot figure out how to plot 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 one column from input data.frame, does it mean it only works for single 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]]
)
Was it helpful?

Solution

Try to use long formatt data with group:

hPlot(x = "x", y = "value", group = "variable", data = reshape2::melt(df, id.vars = "x"))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top