繁体   English   中英

在使用 hc_yAxis_multiples 的 y 轴上添加 plotBands 的 R Highcharter 问题

[英]R Highcharter Issues with adding plotBands on y-axis where hc_yAxis_multiples used

尝试添加 plotBands wrt y 轴 LHS,但出现错误

错误:所有参数都必须命名为列表

来自参考数据集的示例:

library(highcharter)
library(dplyr)

df1 <- data.frame(month = c("Jan", "Feb", "Mar", "Apr", "May", "Jun",
                            "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"),
                  values1 = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2,
                              26.5, 23.3, 18.3, 13.9, 9.6), stringsAsFactors = F)

df1$values2 <- df1$values1/5

图表:

hc <- highchart() %>% 
        hc_yAxis_multiples(
          list(lineWidth = 3),
          list(showLastLabel = T, opposite = TRUE)) %>% 
        hc_title(text = "A nice chart") %>% 
        hc_chart(type = "column") %>% 
        hc_xAxis(categories = df1$month) %>% 
        hc_add_series(data = df1$values1) %>%
        hc_add_series(data = df1$values2, type = "spline", color = "#1FA67A", yAxis = 1)

hc <- hc %>% 
        hc_tooltip(crosshairs = TRUE, shared = TRUE) %>% 
        hc_yAxis(minorGridLineWidth = 0, gridLineWidth = 0,
                 plotBands = list(
                   list(from = 10, to = 20, color = "rgba(68, 170, 213, 0.1)",
                        label = list(text = "A low band")),
                   list(from = 20, to = 25, color = "rgba(0, 0, 0, 0.1)",
                        label = list(text = "A medium band")),
                   list(from = 25, to = 30, color = "rgba(68, 170, 213, 0.1)",
                        label = list(text = "A high band"))
                 ))

由于您使用了hc_yAxis_multiples ,您应该为此列表中的每个轴指定配置。 当您在此之后再次调用 hc_yAxis 时,它不知道将您的 plotBand 等放置在哪个轴上。

尝试这样的事情:

hc <- highchart() %>% 
        hc_yAxis_multiples(
          list(lineWidth = 3,
               minorGridLineWidth = 0, 
               gridLineWidth = 0,
                 plotBands = list(
                   list(from = 10, to = 20, color = "rgba(68, 170, 213, 0.1)",
                        label = list(text = "A low band")),
                   list(from = 20, to = 25, color = "rgba(0, 0, 0, 0.1)",
                        label = list(text = "A medium band")),
                   list(from = 25, to = 30, color = "rgba(68, 170, 213, 0.1)",
                        label = list(text = "A high band"))
                 )
          ),
          list(minorGridLineWidth = 0,gridLineWidth = 0,
          showLastLabel = T, opposite = TRUE)) %>% 
        hc_title(text = "A nice chart") %>% 
        hc_chart(type = "column") %>% 
        hc_xAxis(categories = df1$month) %>% 
        hc_add_series(data = df1$values1) %>%
        hc_add_series(data = df1$values2, type = "spline", color = "#1FA67A", yAxis = 1)

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM