如何在用 highcharter 制作的箱线图中添加均值?

How to add mean in a boxplot made with highcharter?

我想在用 {highcharter} 制作的箱线图中添加均值。 默认情况下,它显示:最小值、最大值、Q1、Q3 和中值。

非常感谢!

library(dplyr)
library(highcharter) 

data(pokemon) 

dat <- data_to_boxplot(pokemon, height)

highchart() %>%
  hc_xAxis(type = "category") %>%
  hc_add_series_list(dat)

dat <- data_to_boxplot(pokemon, height, type_1, name = "height in meters")

highchart() %>%
  hc_xAxis(type = "category") %>%
  hc_add_series_list(dat)

您可以使用以下代码

library(dplyr)
library(highcharter) 

data(pokemon) 

dat <- data_to_boxplot(pokemon, height)

highchart() %>%
  hc_xAxis(type = "category") %>%
  hc_add_series_list(dat)

dat <- data_to_boxplot(pokemon, height, type_1, name = "height in meters")

my_data <- pokemon %>% 
  group_by(type_1) %>% 
  summarise(Mean = mean(height))

highchart() %>%
  hc_xAxis(type = "category") %>%
  hc_add_series_list(dat) %>%
  hc_add_series(name = "Mean",
    data = my_data,
    type = "scatter",
    hcaes(x = "type_1", y = "my_data$Mean")
  )