簡體   English   中英

刪除R中highchart區域圖中的空白

[英]Remove white space in highchart area chart in R

我正在嘗試刪除面積圖(在 R 中使用 highchart 創建)左側和右側的空白區域,如下圖紅色所示。 在此處輸入圖像描述

我的可重現代碼:

library(highcharter)

type <- c("A", "B", "C", "D","A", "B", "C", "D","A", "B", "C", "D")
total <- c(3300, 6080, 2780, 14054, 3638, 6360, 2722, 14148, 2681, 4761, 2080, 10080)
year <- c(2018, 2018, 2018, 2018, 2019, 2019, 2019, 2019, 2020, 2020, 2020, 2020)
df <- data.frame(type, year, total)

highchart() %>%

  hc_chart(type="area") %>%
  hc_add_series(data = subset(df, type == "D"), name = "D", type = "area", hcaes(x = year, y = total)) %>%
  hc_add_series(data = subset(df, type == "B"), name = "B", type = "area", hcaes(x = year, y = total)) %>%
  hc_add_series(data = subset(df, type == "C"), name = "C", type = "area", hcaes(x = year, y = total)) %>%
  hc_add_series(data = subset(df, type == "A"), name = "A", type = "area", hcaes(x = year, y = total)) %>%

  hc_xAxis(title = "", categories = c("2018", "2019", "2020"))

我在網上瀏覽過,但我不懂 JavaScript,所以很難弄清楚。

我將 hc_xAxis 更改為使用 tickPositions 而不是類別。

hc_xAxis(title = "", 
           min = 2018, max = 2020, 
           tickPositions = c(2018, 2019, 2020))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM