我有一个图表,其中 2 个子图堆叠成 1 个较大的图表。我想向第二个图表添加一条水平虚线(y 值=1)。执行此操作的正确代码是什么?
我当前的代码如下:
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")
创建的图表是:
最佳答案
您可以设置plotLines
第二个 y 轴参数:
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")
关于R - Highcharter如何添加水平虚线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58799333/