I have the following code to create a simple column plot and it works fine:
library(highcharter)
d1 <- iris %>% group_by(Species) %>%
summarize(mean_sepal_width = mean(Sepal.Width))
highchart() %>%
hc_chart(type = 'column') %>%
hc_xAxis(categories = d1$Species) %>%
hc_add_series(data = d1$mean_sepal_width)
However, when I subset the input data such that only a single x variable exists, the x axis labels are broken:
d2 <- d %>% filter(Species == 'virginica')
highchart() %>%
hc_chart(type = 'column') %>%
hc_xAxis(categories = d2$Species) %>%
hc_add_series(data = d2$mean_sepal_width)
A potential solution is offered here (Highcharter bar chart cut off x axis label) but I prefer not to use the hchart() function since my actual plot is a lot more complicated.
Is there a way to fix these x axis labels?
Put d2$Species
in a list (or use as.list
). This is a known bug.
highchart() %>%
hc_chart(type = 'column') %>%
hc_xAxis(categories = as.list(d2$Species)) %>%
hc_add_series(data = d2$mean_sepal_width)