Basic colored density curve


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 colored density plot.

# Library
library(ggplot2)

# Dataset
set.seed(14012021)
x <- rnorm(200, mean=4)
df <- data.frame(x)

# Colored density curve
n <- ggplot(df, aes(x=x)) +
  geom_density(color=4,
               fill=4,
               alpha=0.25) +
  theme_bw()
n




Contact

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.