如何将 geom_point 添加到 stat_density_ridges
How to add geom_point to stat_density_ridges
我可以使用此代码绘制 density_ridge。我想在百分位数 0.50 处添加 geom_point 而不更改当前设计。任何帮助将不胜感激。
library(ggplot2)
library(ggridges)
ggplot(iris, aes(x=Sepal.Length, y=Species, fill = factor(stat(quantile)))) +
stat_density_ridges(
geom = "density_ridges_gradient", calc_ecdf = TRUE,
quantiles = 4, quantile_lines = TRUE
)
尝试
p + geom_point(data = aggregate(Sepal.Length ~ Species, iris, median),
aes(x = Sepal.Length, y = Species),
color = "red",
size = 5,
inherit.aes = FALSE)
(看来你一定调用了 viridis
调色板)
数据
library(ggplot2)
library(ggridges)
p <- ggplot(iris, aes(x=Sepal.Length, y=Species, fill = factor(stat(quantile)))) +
stat_density_ridges(
geom = "density_ridges_gradient", calc_ecdf = TRUE,
quantiles = 4, quantile_lines = TRUE
)
我可以使用此代码绘制 density_ridge。我想在百分位数 0.50 处添加 geom_point 而不更改当前设计。任何帮助将不胜感激。
library(ggplot2)
library(ggridges)
ggplot(iris, aes(x=Sepal.Length, y=Species, fill = factor(stat(quantile)))) +
stat_density_ridges(
geom = "density_ridges_gradient", calc_ecdf = TRUE,
quantiles = 4, quantile_lines = TRUE
)
尝试
p + geom_point(data = aggregate(Sepal.Length ~ Species, iris, median),
aes(x = Sepal.Length, y = Species),
color = "red",
size = 5,
inherit.aes = FALSE)
(看来你一定调用了 viridis
调色板)
数据
library(ggplot2)
library(ggridges)
p <- ggplot(iris, aes(x=Sepal.Length, y=Species, fill = factor(stat(quantile)))) +
stat_density_ridges(
geom = "density_ridges_gradient", calc_ecdf = TRUE,
quantiles = 4, quantile_lines = TRUE
)