我想在用 {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)
答案 0 :(得分:1)
您可以使用以下代码
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")
)