gglorenz is an R extension package for drawing Lorenz curves as ggplot2 graphics. It helps visualize how salaries, income, wealth, or performance measures are distributed across a population. section 12.2 section 12.6
A typical gglorenz workflow combines data preparation, plotting, and interpretation:
- Load gglorenz with library(gglorenz) after installing the package if necessary. section 12.2
- Subset the relevant population with dplyr::filter(), then map the measured variable in ggplot(). section 12.6
- Add stat_lorenz(desc = FALSE) to draw the curve in ascending population order. section 12.6
- Use coord_fixed() and a dashed geom_abline() to preserve equal axis proportions and show perfect equality for comparison. section 12.6
- Format both axes as percentages with scales and compare groups by mapping fill and using polygon geometry. section 13.5
NBA salary and win-share distributions
A salary curve for the 1993–94 NBA season is paired with a Gini coefficient of 0.39. A win-share curve for 1990–91 shows that about 1% of players generated 25% of win shares, while a comparison of 1990–91 and 2016–17 curves uses Gini coefficients of 0.56 and 0.49. section 12.6 section 13.5
gini1994 <- filter(gini4, season_end == 1994)
ggplot(gini1994, aes(salary)) +
stat_lorenz(desc = FALSE, color = "red", lwd = 2) +
coord_fixed() +
geom_abline(linetype = "dashed", lwd = 1.5) +
labs(title = "Lorenz Curve\n1993-94 Season",
subtitle = "Gini coefficient = 0.39",
x = "Salary Distribution",
y = "Percentage of NBA Players",
caption = "includes a maximum top 14 salaries for each team") +
scale_x_continuous(labels = percent) +
scale_y_continuous(labels = percent) +
theme(plot.title = element_text(face = "bold"))
Executable code shows the complete ggplot2 construction of a salary Lorenz curve, including stat_lorenz(), fixed coordinates, equality reference, and percentage labels. section 12.6
