问题
I am able to draw density_ridge using this code. I want to add geom_point at percentile 0.50 without changing the current design. Any help would be much appreciated.
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
)
回答1:
Try
p + geom_point(data = aggregate(Sepal.Length ~ Species, iris, median),
aes(x = Sepal.Length, y = Species),
color = "red",
size = 5,
inherit.aes = FALSE)
(along the way you must have called viridis color palette it seems)
data
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
)
来源:https://stackoverflow.com/questions/60141618/how-to-add-geom-point-to-stat-density-ridges