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)
#Dataset
data <- data.frame(
var1 <- rnorm(1000),
var2 <- rnorm(1000, mean=2)
)
# Mirror density curve
p <- ggplot(data, aes(x=x)) +
# Top one
geom_density(aes(x = var1, y = ..density..), fill = "red") +
geom_label(aes(x=4.5, y=0.25, label="Variable 1"), color = "red") +
# Bottom one
geom_density(aes(x = var2, y = -..density..), fill = "blue") +
geom_label(aes(x=4.5, y=-0.25, label="Variable 2"), color = "blue") +
theme_ipsum() # add a theme
p
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.