Reputation: 563
I am trying to make a highcharts plot similar to this (made with ggplot):
This code comes close, but I am uncertain how to change the label to indicate the games
rather than the 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'))
How can I swap out the default labels with labels of my own choosing?
Upvotes: 0
Views: 1363
Reputation: 30474
Would pass your whole data
dataframe into data
argument in hc_add_series
then you can reference in your dataLabels
in format
:
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}'))
Upvotes: 1