Hugo Silva
Hugo Silva

Reputation: 199

Replace axis labels with custom in highcharts r

How can I put letters on the yaxis axis labels?

I want the yaxis labels to be (a,e,i,o,u) instead of (0,25,50,75,100), but I'm getting (a,25,50,75,100)

I'm trying the following

highchart() %>%
  hc_chart(type="bar",zoomType="x") %>%
  hc_yAxis(
    categories = c("a","e","i","o","u"),
    title='',
    tickInterval=25,
    min=0,
    max=100)%>%   
...

thanks

Upvotes: 2

Views: 1661

Answers (1)

m0nhawk
m0nhawk

Reputation: 24238

This is not the issue, the categories in hc_yAxis is assigned sequentially, so in your case it will replace from 0 to 5 (including). You can hack this with seq and replace.

categories_list <- list("0"="a","25"="e","50"="i","75"="o","100"="u")
categories <- seq(0, 100)

for (v in names(categories_list)) {
  categories[[as.integer(v) + 1]] <- categories_list[[v]]
}

highchart() %>%
  hc_add_series(name = "Tokyo", data = citytemp$tokyo) %>% 
  hc_add_series(name = "New York", data = citytemp$new_york) %>%
  hc_add_series(name = "Berlin", data = citytemp$berlin) %>% 
  hc_chart(type="bar",zoomType="x") %>%
  hc_yAxis(
    categories = categories,
    title='',
    tickInterval=25,
    min=0,
    max=100)

And the result:

Upvotes: 3

Related Questions