我想在我的骑行图中画一条线来表示平均值。内置的分位数参数以我想要的样式画一条线,但在中位数。我怎样才能平均画一个,最好不使用geom_vline()或在 ggplot 构建对象上采摘但留在 ggridges 生态中?
library(tidyverse)
library(ggridges)
#adding a column for the mean of each Species of the iris dataframe
iris_meaned <- iris %>%
group_by(Species) %>%
mutate(mean_petal_len = mean(Petal.Length)) %>%
ungroup()
iris_meaned %>%
ggplot() +
geom_density_ridges(
aes(x = Petal.Length, y = Species, fill = Species),
quantile_lines = T, quantiles = 2 #adding lines for the median
) +
geom_text(
aes(x = mean_petal_len, y = Species, label = round(mean_petal_len, 2)),
size = 2, nudge_x = 0.03, nudge_y = 0.35
) +
theme_classic() +
theme(
axis.title = element_blank(),
legend.position = "None"
)