Kevin Burnham
Kevin Burnham

Reputation: 563

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

I am trying to make a highcharts plot similar to this (made with ggplot): enter image description here

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

Answers (1)

Ben
Ben

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}'))

plot with custom labels in highcharter

Upvotes: 1

Related Questions