【发布时间】:2020-07-20 17:34:34
【问题描述】:
我正在尝试在高图中的 x 轴上对类别进行分组。它工作正常。我想隐藏 Jan-Dec 标签中的刻度,但在 Q1-Q4 标签中显示刻度。如果我使用 tickwidth = 0 它会删除两个类别的刻度。我只想在分组类别中显示它。
注意:我也愿意接受 highcharts 解决方案(不仅仅是 highcharts 的 R 包装器)
library(purrr) # map function to make grouped categories argument
library(dplyr) # for select function
df1 = data.frame("label"= c('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'),
"label2" = c('Q1', 'Q1', 'Q1', 'Q2', 'Q2', 'Q2',
'Q3', 'Q3', 'Q3', 'Q4', 'Q4', 'Q4'),
"value" = c(49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4)
)
categories_grouped <- df1 %>%
group_by(name = label2) %>%
do(categories = .$label) %>%
list_parse()
highchart() %>%
hc_xAxis(categories = categories_grouped,
labels = list(rotation = 0, style = list(color = '#3777ac', fontWeight = '400'),
groupedOptions = list(list(style = list(color = '#3777ac', fontWeight = '600'))))) %>%
hc_add_series(data = df1, type = "column", hcaes(y = value),
showInLegend = FALSE)
【问题讨论】: