在highcharts中用自定义替换轴标签

时间:2018-11-17 21:37:20

标签: javascript r highcharts r-highcharter

如何在yaxis轴标签上放置字母?

我希望yaxis标签为(a,e,i,o,u)而不是(0,25,50,75,100),但是我得到的是(a,25,50,75,100)

我正在尝试以下

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

谢谢

1 个答案:

答案 0 :(得分:1)

这不是问题,categories中的hc_yAxis是按顺序分配的,因此在您的情况下,它将从0替换为5(包括)。您可以使用seq修改并替换。

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)

结果: