Highcharter 无法删除 y 轴标签

问题描述 投票:0回答:1

尝试删除 yAxis 标签,理想情况下将它们移动到条形图的末尾,值通常位于条形图的末尾,因为我需要图表的左侧干净。

来自 highcharts 的参考资料已尝试以下方法但无济于事:

hc_yAxis(dataLabels = list(enabled = FALSE), 
hc_yAxis(Labels = list(enabled = FALSE)
hc_yAxis(dataLabels = list(enabled = TRUE, align = 'right')

从这里开始 如何从 R Highcharter 中删除“值”

hc_yAxis(showLabel = FALSE)

尽管我认为如果 yAxis_multiples 现在已弃用,该方法可能会被弃用。

我可以煞费苦心地注释标签,但仍然存在无法删除 yAxis 标签的问题。

test <- tibble::tribble(
  ~year,    ~Type, ~total,
  2020,    "low",     45,
  2020, "medium",     52,
  2020,   "high",     98,
  2021,    "low",     60,
  2021, "medium",     83,
  2021,   "high",     80,
  2022,    "low",     64,
  2022, "medium",     34,
  2022,   "high",     20,
  2023,    "low",     62,
  2023, "medium",     47,
  2023,   "high",     58)

test <- mutate(test, Type = fct(Type), year = as.character(year))

highchart() %>% 
  hc_plotOptions(series = list(pointWidth = 15)) %>% 
  hc_xAxis(categories = test$Type, labels = list(style = list(
    color = '#344a5e',fontFamily = "Segoe UI",fontWeight = 600))) %>% 
  hc_yAxis(dataLabels = list(enabled = FALSE)) %>%
  hc_add_series(dataSorting = list(enabled = TRUE),
                data = test, type = 'bar', hcaes(x = Type, y = total, group = year),
                dataLabels = list(enabled = FALSE, style = list(color ='#344a5e',
                                                                fontFamily = "Segoe UI",
                                                                fontWeight = 400))) %>% 
  hc_title(text = "Year on Year Comparison") %>%
  hc_subtitle(text = "") %>%
  hc_caption(text = "ref data") %>%
  hc_tooltip(sort = TRUE, table = TRUE) %>% 
  hc_size(height = 600) %>% 
  hc_add_theme(thm_bar)
    

任何指导表示赞赏。

r highcharts r-highcharter
1个回答
0
投票

在您的示例中,您应该使用 xAxis 函数。您可以使用

Labels = list(enabled = FALSE))
删除标签,如下所示:

library(dplyr)
library(highcharter)
library(forcats)
test <- mutate(test, Type = fct(Type), year = as.character(year))

highchart() %>% 
  hc_plotOptions(series = list(pointWidth = 15)) %>% 
  hc_xAxis(categories = test$Type, labels = list(style = list(
    color = '#344a5e',fontFamily = "Segoe UI",fontWeight = 600),
    enabled = FALSE)) %>%
  #hc_yAxis(dataLabels = list(enabled = FALSE)) %>%
  hc_add_series(dataSorting = list(enabled = TRUE),
                data = test, type = 'bar', hcaes(x = Type, y = total, group = year),
                dataLabels = list(enabled = FALSE, style = list(color ='#344a5e',
                                                                fontFamily = "Segoe UI",
                                                                fontWeight = 400))) %>% 
  hc_title(text = "Year on Year Comparison") %>%
  hc_subtitle(text = "") %>%
  hc_caption(text = "ref data") %>%
  hc_tooltip(sort = TRUE, table = TRUE) %>% 
  hc_size(height = 600) 

创建于 2024-03-25,使用 reprex v2.0.2

© www.soinside.com 2019 - 2024. All rights reserved.