Multi-Histogram Distributions

Comparing histograms across classes can provide useful information about the nature of the data you are working with. The implementation belows demostrates how to achieve this using ggplot. I begin by generating random data for the distribution.

library(ggthemr)
library(ggplot2)

ggthemr("dust")


x = rnorm(n = 10000, mean = 21, sd = 1.5)
y = rnorm(n = 10000, mean = 25, sd = 1.5)
z = rnorm(n = 10000, mean = 19, sd = 1.8)
data = data.frame( values = c(x, y, z),
    class = rep(c("A", "B", "C"), each = length(x)))

head(data)
A data.frame: 6 × 2
valuesclass
123.74437A
216.92297A
319.04337A
419.34535A
521.86623A
620.00213A
options(repr.plot.width = 10, repr.plot.height = 8)

histograms = ggplot( data, aes( x = values, 
                                fill = class )) +
                        geom_histogram( color = "black", bins=30) +
                        ggtitle("Multi-Class Histogram Distribution Plot ")

histograms
Multiple Class Histogram Plot