[英]R Highcharter Issues with adding plotBands on y-axis where hc_yAxis_multiples used
Trying to add plotBands wrt y-axis LHS, but getting errors尝试添加 plotBands wrt y 轴 LHS,但出现错误
Error: All arguments must be named list错误:所有参数都必须命名为列表
Example from the reference dataset:来自参考数据集的示例:
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
Charts:图表:
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"))
))
Since you used hc_yAxis_multiples
, you should specify the configurations for each axis inside this list.由于您使用了hc_yAxis_multiples
,您应该为此列表中的每个轴指定配置。 When you call hc_yAxis again after this, it doesn't know which axis to put your plotBand etc..当您在此之后再次调用 hc_yAxis 时,它不知道将您的 plotBand 等放置在哪个轴上。
Try something like this:尝试这样的事情:
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.