gpt4 book ai didi

R - Highcharter如何添加水平虚线?

转载 作者:行者123 更新时间:2023-12-03 08:51:14 28 4
gpt4 key购买 nike

我有一个图表,其中 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")

创建的图表是:

enter image description here

最佳答案

您可以设置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")

enter image description here

关于R - Highcharter如何添加水平虚线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58799333/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com