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

标签 r highcharts r-highcharter

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

相关文章:

javascript - 如何删除移动应用程序中的多余空间?

javascript - R Highcharter 自定义图例以仅显示某些值

r - 在旋转坐标上查找轴线

r - 对数据应用函数 n 次

string - 一组字符串的 R 直方图和描述性统计数据

r - 如何在 Rmarkdown 中将距离矩阵格式化为数组?

javascript - Highcharts x 轴日期分组不起作用

javascript - Highcharts 跳过第二个 x 轴标签

R Highcharter 缩放选定区域

r - 使用 Highcharter 在 R 中的 Highcharts 饼图上显示标签名称和值