样式分组类别

时间:2021-07-15 09:23:30

标签: r highcharts axis-labels

我正在尝试在 R 中为 highcharter 设置样式,在 x 轴上使用分组标签。

如何为标签周围的框边框着色?

enter image description here

代码:

  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 个答案:

答案 0 :(得分:2)

您可以通过轴的 tickColor 设置框的边框颜色:

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

相关问题