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 mirror density plot.
# Libraries
library(ggplot2)
library(hrbrthemes)
# Creation of dataset
data <- data.frame(
var1 <- rnorm(1000),
var2 <- rnorm(1000, mean=2)
)
# Mirror density curve
ggplot(data, aes(x=x)) +
# Top one
geom_density(aes(x = var1, y = ..density..), fill = "#e41a1c") +
geom_label(aes(x=4.5, y=0.25, label="Variable 1"), color = "#e41a1c") +
# Bottom one
geom_density(aes(x = var2, y = -..density..), fill = "#377eb8") +
geom_label(aes(x=4.5, y=-0.25, label="Variable 2"), color = "#377eb8") +
theme_ipsum()
This document is a work of the statistics team in the Biostatistics and Medical Information Department at Saint-Louis Hospital in Paris (SBIM).
Developed and updated by Noémie Bigot and Anouk Walter-Petrich
noemie.bigot@aphp.fr; anouk.walter-petrich@u-paris.fr
Based on The R Graph Gallery by Yan Holtz.