繁体   English   中英

轴 Label 截断在 highcharter 条形图中

[英]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))

在此处输入图像描述

但是只有一行/类别的数据框的相同代码将删除类别 label。

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

在此处输入图像描述

无论类别数量如何,如何确保 label 正确显示?

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

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM