这看起来和预期的一样:
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))

如何确保标签正确显示,而不考虑类别的数量?
发布于 2019-11-12 08:03:33
在这里,将categories作为列表传递会有所帮助。
highchart() %>%
hc_yAxis(title = "") %>%
hc_xAxis(categories = as.list(df$surveillance_diag)) %>%
hc_add_series(data = df, type = "bar", hcaes(x = surveillance_diag, y = y, color = color))

https://stackoverflow.com/questions/58807372
复制相似问题