4.10 Grouped kernel density plots

We can compare groups on a numeric variable by superimposing kernel density plots in a single graph.

# plot the distribution of salaries 
# by rank using kernel density plots
ggplot(Salaries, 
       aes(x = salary, 
           fill = rank)) +
  geom_density(alpha = 0.4) +
  labs(title = "Salary distribution by rank")