# Simple density plot
data("mtcars")
ggdensity(mtcars, x = "mpg", fill = "red") +
scale_x_continuous(limits = c(-1, 50)) +
stat_central_tendency(type = "mean", linetype = "dashed")
# Color by groups
data(iris)
ggdensity(iris, "Sepal.Length", color = "Species") +
stat_central_tendency(aes(color = Species), type = "median", linetype = 2)
# Use geom = "point" for central tendency
data(iris)
ggdensity(iris, "Sepal.Length", color = "Species") +
stat_central_tendency(
aes(color = Species), type = "median",
geom = "point", size = 4
)
# Facet
ggdensity(iris, "Sepal.Length", facet.by = "Species") +
stat_central_tendency(type = "mean", color = "red", linetype = 2) +
stat_central_tendency(type = "median", color = "blue", linetype = 2)
Run the code above in your browser using DataLab