liveBook · Manning

Cut_short_scale() function

As explained in Statistics Slam Dunk

The cut_short_scale() function from the scales package formats large numeric values with abbreviated scale suffixes such as M for millions.

cut_short_scale() is a scales-package helper for making large numeric values easier to read on ggplot2 axes. It replaces long values with abbreviated scale suffixes, such as M for millions. Combined with label_dollar(), it turns 20000000 into a readable $20 M label. section 10.4.2

Use it inside scale_x_continuous() or scale_y_continuous() through the scale_cut argument. The underlying data remains numeric, while only the displayed axis labels are shortened. section 10.4.2 section 10.4.3

Typical applications include:

  • Format team payrolls in dot plots without displaying unwieldy seven- or eight-digit numerals. section 10.4.2
  • Display average payrolls in lollipop charts while preserving the original numeric means for plotting and comparison. section 10.4.3
  • Label salary spending per regular-season win with values such as $1M, $2M, and $3M. section 11.4.2

Format an NBA payroll axis

A dot plot can keep payroll values numeric and apply readable dollar labels with: scale_x_continuous(labels = label_dollar(scale_cut = cut_short_scale())). The same pattern works for a y-axis by replacing scale_x_continuous() with scale_y_continuous().

salaries2000 <- select(salaries, Team, s2000, pc2000)
salaries2000 <- na.omit(salaries2000)

dot1 <- ggplot(salaries2000) +
 geom_point(aes(x = s2000, y = reorder(Team, s2000), 
                color = factor(pc2000)), size = 3) +
 labs(title= "NBA Team Payrolls (USD)", 
      subtitle = "1999-2000", 
      x = "Team Payroll", 
      y = "") +
 scale_x_continuous(labels = label_dollar(scale_cut = cut_short_scale())) +
 theme(plot.title = element_text(face = "bold")) + 
 scale_color_manual(name = "", 
                    labels = c("No playoffs", 
                               "Made playoffs", 
                               "Won title"), 
                    values = c("0" = "navy", 
                               "10" = "gold3", 
                               "11" = "red")) +
 theme(legend.position = "bottom") +
 theme(axis.text.x = element_text(angle = 45, hjust = 1))

Inspect a complete payroll dot-plot listing that combines cut_short_scale() with dollar prefixes, reordered teams, outcome colors, and rotated axis text. section 10.4.2

How Statistics Slam Dunk covers it

How deep it goes
Demonstrates axis-label integration and practical chart examples, but does not explain the helper’s internal scaling algorithm.
Examples
Uses NBA payroll dot plots, payroll-comparison lollipop charts, and salary-per-win bar charts.
What it assumes
Assumes familiarity with ggplot2 scales and label_dollar(), while demonstrating the formatting pattern through concrete NBA data.
What you can do after
Apply it via scales and ggplot2 to shorten monetary axis labels without changing plotted values.
How it connects
Connects scales, ggplot2, scale_x_continuous(), scale_y_continuous(), and label_dollar().

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.