highcharter:如何自定义柱状图上的标签

highcharter: how can I customize the labels on a column plot

我正在尝试制作一个类似于此的高图图(使用 ggplot 制作):

这段代码很接近,但我不确定如何更改标签以指示 games 而不是 win_rate。

data = data.frame(player = c('Edwin', 'Ahmad', 'Sonia', 'Jessica'),
                  games = c(10, 20, 15, 40),
                  win_rate = c(.5, .2, .8, .4))




highchart() %>%
      highcharter::hc_chart(type = 'column', zoomType = 'x') %>%
      highcharter::hc_plotOptions(column = list(stacking = 'normal'))  %>%
      highcharter::hc_xAxis(categories = data$player) %>%
      highcharter::hc_add_series(name = 'Win Rate', 
                                 data = data$win_rate,  
                                 dataLabels = list(enabled = TRUE, verticalAlign = 'top'))

如何用我自己选择的标签替换默认标签?

会将整个 data 数据帧传递给 hc_add_series 中的 data 参数,然后您可以在 format 中的 dataLabels 中引用:

highchart() %>% 
  hc_xAxis(categories = data$player) %>% 
  hc_add_series(data = data, type = 'column', hcaes(x = player, y = win_rate),
                dataLabels = list(enabled = TRUE, format='{point.games}'))