Search code examples
rhighchartsdata-visualizationr-highcharter

Display only groups in Highcharter


I'm using something similar to the following code to display bar chart groupwise:

library(purrr) # map function to make grouped categories argument
library(dplyr) # for select function 

data(mpg, package = "ggplot2")

mpgg <- mpg %>% 
  filter(class %in% c("suv", "compact", "midsize")) %>% 
  group_by(class, manufacturer) %>% 
  summarize(count = n())

categories_grouped <- mpgg %>% 
  group_by(name = class) %>% 
  do(categories = .$manufacturer) %>% 
  list_parse()

highchart() %>% 
  hc_xAxis(categories = categories_grouped) %>% 
  hc_add_series(data = mpgg, type = "bar", hcaes(y = count, color = manufacturer),
                showInLegend = FALSE)

I'm getting the following chart:

Highchart Group Categories Wise

Because of the misalignment, I just want to display groups without categories. I have tried several solutions but there is always some alignment issue.

Any solutions?


Solution

  • If you don't need two groups of categories, you can just define standard categories without grouped-categories.js module like in this JS example: jsfiddle.net/BlackLabel/29kgtp3u