Highcharter R 中工具提示和轴的日期格式

Date format for tooltip and axis in Highcharter R

我有以下数据集:

library(highcharter)
datasample <- data.frame(month = c("2020-01-01","2020-02-01","2020-03-01"),
                         sales = c(10000,15000,2000),
                         margin = c(0.34,0.33,0.31))

datasample$month <- as.Date(datasample$month)

我想要绘制每月的销售额,但要在辅助轴上添加边距。所以我尝试了这段代码:

highchart() %>% 
  hc_yAxis_multiples(
    list(lineWidth = 3),
    list(showLastLabel = FALSE, opposite = TRUE)
  ) %>% 
  hc_add_series(datasample, hcaes(x = month, y = sales), 
                yAxis=0, type = "area", name = "Sales") %>%
  hc_add_series(datasample, hcaes(x = month, y = margin), 
                yAxis=1, type = "line", name = "Margin") 

该图的问题在于日期被格式化为一长串数字(可能是时间戳)。我尝试添加此代码,但仅适用于轴,不适用于工具提示:

%>%
  hc_xAxis(labels = list(format = '{value:%m %Y}'))

拜托,你能帮我解决这个问题吗?谢谢。

hc_xAxis中使用type = "datetime"

library(highcharter)

highchart() %>% 
  hc_yAxis_multiples(
    list(lineWidth = 3),
    list(showLastLabel = FALSE, opposite = TRUE)
  ) %>% 
  hc_add_series(datasample, hcaes(x = month, y = sales), 
                yAxis=0, type = "area", name = "Sales") %>%
  hc_add_series(datasample, hcaes(x = month, y = margin), 
                yAxis=1, type = "line", name = "Margin") %>%
  hc_xAxis(dateTimeLabelFormats = list(day = '%m  %Y'), type = "datetime")