r - highcharter:如何使用 hcaes 函数制作分组图
问题描述
下面的图在 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}'))
推荐阅读
- c - C、共享一个地址但不同的输出
- reactjs - react + typescript 如何修复道具类型错误
- javascript - API 不会在 JavaScript 中收集所需的数据
- c - 如何在程序执行期间使用字符串文字和字符数组构造字符串文字而不包括字符串库?
- python - 如何将数据列表附加到 CSV 中的多个新列?
- mysql - MySQL SELECT 与另一个表中的数据
- javascript - Electron React Boilerplate 未导航到新路线
- xamarin - WebAuthenticator 浏览器上的取消按钮导致 Domain=com.apple.AuthenticationServices.WebAuthenticationSession Code=1
- hyperledger-fabric - 错误 - 调用approvyformyorg函数时抛出通道不存在
- django - 获取模型的所有实例,同时根据字段删除重复项,同时附加同一字段的计数