liveBook · Manning

Stat_lorenz() function

As explained in Statistics Slam Dunk

The stat_lorenz() function is a gglorenz plotting statistic that computes and draws Lorenz curves from mapped data.

stat_lorenz() is a gglorenz plotting statistic for drawing Lorenz curves inside a ggplot2 workflow. Map a numeric variable, choose the population order, and compare the curve with a perfect-equality diagonal. section 12.6 section 13.5

A typical workflow is:

  • Filter the data to one season or comparison group. section 12.6
  • Initialize ggplot() with the filtered data and the variable whose distribution will be evaluated. section 12.6
  • Add stat_lorenz(desc = FALSE) for ascending population order; set color, line width, or geom = "polygon" as needed. section 12.6 section 13.5
  • Use coord_fixed(), geom_abline(), and percentage scales to make inequality comparisons easier to interpret. section 12.6

NBA salary distribution

Filter gini4 to season_end == 1994, map salary, and add stat_lorenz(desc = FALSE, color = "red", lwd = 2). The resulting curve accompanies a Gini coefficient of 0.39 for the 1993–94 season. section 12.6

ggplot(gini9117, aes(WS, fill = Year)) +
 stat_lorenz(geom = "polygon", desc = FALSE) +
 coord_fixed() +
 geom_abline(linetype = "dashed") +
 labs(title = "Lorenz Curve\n1990-91 versus 2016-17 Seasons", 
      subtitle = "Gini coefficients = 0.56 and 0.49",
      x = "Win Share 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"))

Inspect a consolidated stat_lorenz() plot comparing 1990–91 and 2016–17 win-share distributions with separate fills. section 13.5

How Statistics Slam Dunk covers it

How deep it goes
Explains filtering, aesthetic mapping, population ordering, styling, reference lines, aspect ratio, and comparative geometries.
Examples
Uses NBA salary curves for 1993–94 and win-share curves for 1990–91, 2016–17, and their comparison.
What it assumes
Assumes basic dplyr filtering and ggplot2 mappings while demonstrating the Lorenz-curve plotting syntax from those foundations.
What you can do after
Builds and compares Lorenz curves with gglorenz and ggplot2 using filtered, mapped distribution data.
How it connects
Connects Lorenz curves and Gini coefficients with ggplot2, gglorenz, dplyr, coordinate scaling, and reference lines.

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.