我正在尝试使用 Highcharter 创建一个带有分组的堆积条形图,并且需要在不使用该hchart()
函数的情况下创建它。我有以下代码(hchart()
部分有效)。
data <- data.frame(
building = c("Building A", "Building A", "Building B", "Building B"),
type = c("Rent", "Owned"),
measure = c(100, 35, 124, 150),
measure_target = c(95, 20, 122, 145)
)
# This works
hchart(data, "column", hcaes(x = "building", y = "measure", group = "type")) %>%
hc_plotOptions(column = list(stacking = "normal"))
# How do we go from the above, to something like this?
highchart() %>%
hc_xAxis(categories = data$building) %>%
hc_add_series(type = "column", data = data$measure) %>%
hc_plotOptions(column = list(stacking = "normal"))
预期输出如下。这样做的最终目标是添加堆叠的条形图,然后使用另一个 hc_add_series 在measure_target
列中添加一系列点(因此比较实际值与目标值)。
除了有两个堆叠的条和一条用于目标的线外,例如: