这看起来像预期的那样:
df <- structure(list(surveillance_diag = c("Meningitis", "Sepsis"),
y = c(1239L, 7850L), color = c("#1f78b4", "#e31a1c"),
freq = c(14, 86)), row.names = c(NA, -2L), class = c("tbl_df", "tbl", "data.frame"))
library(highcharter)
library(magrittr)
highchart() %>%
hc_yAxis(title = "") %>%
hc_xAxis(categories = df$surveillance_diag) %>%
hc_add_series(data = df, type = "bar", hcaes(x = surveillance_diag, y = y, color = color))
但是,只有一个数据行只有一个行/类别的相同代码将剪切类别标签。
df <- df[1, ]
highchart() %>%
hc_yAxis(title = "") %>%
hc_xAxis(categories = df$surveillance_diag) %>%
hc_add_series(data = df, type = "bar", hcaes(x = surveillance_diag, y = y, color = color))
无论类别数如何,如何确保标签正确显示?