轴标签在 highcharter Barplot 中被截断

Axis Label Truncated in highcharter Barplot

这看起来符合预期:

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))

但是只有一个数据框的相同代码row/category会切断类别标签。

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))

如何保证不管分类多少都能正确显示标签?

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))