Style grouped categories

Viewed 77

I am trying to style a highcharter, in R, with grouped labels on the x-axis.

How do I color the border of the boxes around the labels?

enter image description here

Code:

  mpgg <- mpg %>% 
    filter(!manufacturer %in% c("volkswagen", "chevrolet")) %>% 
    filter(class %in% c("compact", "midsize", "subcompact")) %>% 
    group_by(class, manufacturer) %>% 
    summarize(count = n()) %>% 
    ungroup()

  categories_grouped <- x %>%
    select(class, manufacturer) %>%
    group_by(name = class) %>% 
    summarise(categories = list(manufacturer)) %>% 
    list_parse()
  
  
  hchart(
    mpgg,
    "column", 
    name = "Cars",
    hcaes(y = count)
  ) %>% 
    hc_xAxis(categories = categories_grouped, 
      labels = list(style = list(fontSize = "10px"))
    ) %>%
    hc_add_dependency("plugins/grouped-categories.js")
1 Answers

You could set the border color of the boxes via the tickColor of the axis:

library(highcharter)
library(ggplot2)
library(dplyr)

mpgg <- mpg %>% 
  filter(!manufacturer %in% c("volkswagen", "chevrolet")) %>% 
  filter(class %in% c("compact", "midsize", "subcompact")) %>% 
  group_by(class, manufacturer) %>% 
  summarize(count = n()) %>% 
  ungroup()
#> `summarise()` has grouped output by 'class'. You can override using the `.groups` argument.

categories_grouped <- mpgg %>%
  select(class, manufacturer) %>%
  group_by(name = class) %>% 
  summarise(categories = list(manufacturer)) %>% 
  list_parse()


hchart(
  mpgg,
  "column", 
  name = "Cars",
  hcaes(y = count)
) %>% 
  hc_xAxis(categories = categories_grouped, 
           labels = list(style = list(fontSize = "10px")),
           tickColor = '#FF0000'
  ) %>%
  hc_add_dependency("plugins/grouped-categories.js")

Related