highcharter:如何使用 hcaes 函数制作分组图
highcharter: how do I make a grouped plot using the hcaes function
下图在 highcharter 中制作了堆积柱形图。我试图使它成为一个分组柱形图,但是我添加堆栈字段未能达到预期的结果。
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))
highcharter::highchart() %>%
highcharter::hc_xAxis(categories = data$player) %>%
highcharter::hc_plotOptions(column = list(stacking = 'normal')) %>%
highcharter::hc_add_series(data = data %>% dplyr::filter(week == 1), type = 'column', highcharter::hcaes(x = player, y = win_rate, stack = week),
dataLabels = list(enabled = TRUE, format='{point.games}')) %>%
highcharter::hc_add_series(data = data %>% dplyr::filter(week == 2), type = 'column', highcharter::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}'))
下图在 highcharter 中制作了堆积柱形图。我试图使它成为一个分组柱形图,但是我添加堆栈字段未能达到预期的结果。
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))
highcharter::highchart() %>%
highcharter::hc_xAxis(categories = data$player) %>%
highcharter::hc_plotOptions(column = list(stacking = 'normal')) %>%
highcharter::hc_add_series(data = data %>% dplyr::filter(week == 1), type = 'column', highcharter::hcaes(x = player, y = win_rate, stack = week),
dataLabels = list(enabled = TRUE, format='{point.games}')) %>%
highcharter::hc_add_series(data = data %>% dplyr::filter(week == 2), type = 'column', highcharter::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}'))