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.

# Libraries
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)
n




Contact

This document is a work by Emma Lafaurie (emma.lafaurie@inserm.fr) for the SBIM (Service de Biostatistique et Information Médicale) at Saint-Louis Hospital in Paris.
Based on the template of Yan Holtz.