下面的图以高图的形式显示了堆积的柱状图。我试图使它成为一个分组的柱形图,但是我添加的堆栈字段未能实现所需的结果。
data = data.frame(player = rep(c('Edwin', 'Ahmad', 'Sonia', 'Jessica'), 2),
games = c(10, 20, 15, 40, 12, 57, 18, 49),
win_rate = c(.5, .2, .8, .4, .1, .7, .3, .43),
week = rep(c(1,2), 4))
highchart() %>%
hc_xAxis(categories = data$player) %>%
highcharter::hc_plotOptions(column = list(stacking = 'normal')) %>%
hc_add_series(data = data %>% filter(week == 1), type = 'column', hcaes(x = player, y = win_rate, stack = week),
dataLabels = list(enabled = TRUE, format='{point.games}')) %>%
hc_add_series(data = data %>% filter(week == 2), type = 'column', hcaes(x = player, y = win_rate, stack = week),
dataLabels = list(enabled = TRUE, format='{point.games}'))
这类似于您想要的吗?
highchart() %>%
hc_xAxis(categories = data$player) %>%
hc_add_series(data = data %>% filter(week == 1), type = 'bar', hcaes(x = player, y = win_rate, group = week),
dataLabels = list(enabled = TRUE, format='{point.games}')) %>%
hc_add_series(data = data %>% filter(week == 2), type = 'bar', hcaes(x = player, y = win_rate, group = week),
dataLabels = list(enabled = TRUE, format='{point.games}'))