简体   繁体   中英

Axis Label Truncated in highcharter Barplot

This looks as expected:

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

在此处输入图像描述

But the same code with a data frame of only one row/category will cut the category 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))

在此处输入图像描述

How can I ensure that the label is properly displayed regardless of the number of categories?

Passing categories as a list helps here.

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

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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