Trying to add plotBands wrt y-axis LHS, but getting errors
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. When you call hc_yAxis again after this, it doesn't know which axis to put your plotBand etc..
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.