Reputation: 726
I have a graph with 2 subgraphs stacked into 1 larger graph. I would like to add a horizontal dashed line to second graph (at a y value =1). What is the correct code to do this?
My current code is as follows:
library(xts)
library(highcharter)
dates = seq(as.Date("2012-01-01"), as.Date("2012-01-04"), by="day")
x1 = xts(c(2,3,1,5), dates)
x2 = xts(c(1,1.5,2,1), dates)
highchart(type = "stock") %>%
hc_yAxis_multiples(
list(top = "0%", height = "60%", title = list(text = "Var1")),
list(top = "60%", height = "40%", title = list(text = "Var2"))) %>%
hc_add_series(x1, yAxis=0, compare="percent", color="blue") %>%
hc_add_series(x2, yAxis=1, color="black")
The graph created is:
Upvotes: 2
Views: 3071
Reputation: 2718
You can set plotLines
parameter to the second y-axis:
highchart(type = "stock") %>%
hc_yAxis_multiples(
list(top = "0%", height = "60%", title = list(text = "Var1")),
list(top = "60%", height = "40%", title = list(text = "Var2"),
plotLines = list(list(value = 1, color = "red", width = 2,
dashStyle = "shortdash")))
) %>%
hc_add_series(x1, yAxis = 0, compare = "percent", color = "blue") %>%
hc_add_series(x2, yAxis = 1, color = "black")
Upvotes: 3
Reputation: 9505
Maybe a workaround, adding a third line to your plot:
library(xts)
library(highcharter)
dates = seq(as.Date("2012-01-01"), as.Date("2012-01-04"), by="day")
x1 = xts(c(2,3,1,5), dates)
x2 = xts(c(1,1.5,2,1), dates)
x3 = xts(rep(1, length(dates)), dates) # here the third line
highchart(type = "stock") %>%
hc_yAxis_multiples(
list(top = "0%", height = "60%", title = list(text = "Var1")),
list(top = "60%", height = "40%", title = list(text = "Var2"))) %>%
hc_add_series(x1, yAxis=0, compare="percent", color="blue") %>%
hc_add_series(x2, yAxis=1, color="black")%>%
# here you add to your plot
hc_add_series(x3, yAxis=1, color="red", dashStyle = "DashDot")
Upvotes: 2