Histograms are vital for examining distribution symmetry, kurtosis,
and modal patterns. Here, we present dual distribution plots for both
Height and Weight, complete with: * Binned counts (histograph bars) *
Overlaid Kernel Density Estimates (solid lines) * Parametric Normal
distribution curves (dashed lines) * Centrality indicators (Mean and
Median)
# Histogram for Body Weight
p_hist_weight <- ggplot(df_clean, aes(x = weight)) +
geom_histogram(aes(y = after_stat(density)), bins = 35, fill = "#3498db", color = "white", alpha = 0.7) +
geom_density(color = "#2c3e50", size = 1, adjust = 1.2) +
stat_function(
fun = dnorm,
args = list(mean = mean(df_clean$weight), sd = sd(df_clean$weight)),
color = "#e74c3c", linetype = "dashed", size = 0.9
) +
geom_vline(aes(xintercept = mean(weight)), color = "#e74c3c", linetype = "solid", size = 1) +
geom_vline(aes(xintercept = median(weight)), color = "#2c3e50", linetype = "dotted", size = 1) +
annotate("text", x = mean(df_clean$weight) - 4, y = 0.12,
label = paste0("Mean: ", round(mean(df_clean$weight), 1), " kg"),
color = "#e74c3c", size = 3.5, fontface = "bold") +
labs(
title = "A: Distribution of Body Weight",
subtitle = "Kernel density (dark) vs. Normal curve (red dashed)",
x = "Weight (kg)",
y = "Density"
)
# Histogram for Height
p_hist_height <- ggplot(df_clean, aes(x = height)) +
geom_histogram(aes(y = after_stat(density)), bins = 35, fill = "#2ecc71", color = "white", alpha = 0.7) +
geom_density(color = "#2c3e50", size = 1, adjust = 1.2) +
stat_function(
fun = dnorm,
args = list(mean = mean(df_clean$height), sd = sd(df_clean$height)),
color = "#e74c3c", linetype = "dashed", size = 0.9
) +
geom_vline(aes(xintercept = mean(height)), color = "#e74c3c", linetype = "solid", size = 1) +
geom_vline(aes(xintercept = median(height)), color = "#2c3e50", linetype = "dotted", size = 1) +
annotate("text", x = mean(df_clean$height) + 5, y = 0.10,
label = paste0("Mean: ", round(mean(df_clean$height), 1), " cm"),
color = "#e74c3c", size = 3.5, fontface = "bold") +
labs(
title = "B: Distribution of Height",
subtitle = "Kernel density (dark) vs. Normal curve (red dashed)",
x = "Height (cm)",
y = "Density"
)
# Arrange side-by-side using gridExtra
grid.arrange(p_hist_weight, p_hist_height, ncol = 2)