liveBook · Manning

Gglorenz

As explained in Statistics Slam Dunk

gglorenz is an R extension package for constructing Lorenz curves within ggplot2 graphics.

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

How Statistics Slam Dunk covers it

How deep it goes
Explains package loading, data filtering, stat_lorenz() arguments, axis alignment, reference lines, and grouped comparisons.
Examples
Uses NBA salary and win-share data across individual seasons and multi-season comparisons.
What it assumes
Assumes basic R package loading and ggplot2 syntax while demonstrating filtering and Lorenz plotting from working datasets.
What you can do after
Builds and compares Lorenz curves through R, ggplot2, and the stat_lorenz() function.
How it connects
Connects Lorenz curves with ggplot2, Gini coefficients, dplyr filtering, and scales-based percentage formatting.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.