A density plot is a representation of the distribution of a numeric
variable. It is a smoothed version of the histogram and is used in the
same kind of situation.
Here is a basic example of a density plot.
# Library
library(ggplot2)
# Dataset
set.seed(14012021)
x <- rnorm(200, mean=4)
df <- data.frame(x)
# Density curve in ggplot2
p <- ggplot(df, aes(x=x)) +
geom_density() +
theme_bw()
p
This document is a work of the statistics team in the Biostatistics and Medical Information Department at Saint-Louis Hospital in Paris (SBIM).
Based on The R Graph Gallery by Yan Holtz.