Hidden Mappings
in the
Grammar of Graphics

Paul Murrell
ggplot(pets) +
    geom_col(aes(x=millions, y=country, fill=pet), position="dodge") +
    ggtitle("Global Pet Ownership")

ggplot(pets) +
    geom_col(aes(x=millions, y=country, fill=pet), position="dodge") +
    scale_x_continuous(guide=guide_axis()) +
    scale_y_discrete(guide=guide_axis()) +
    scale_colour_discrete(guide=guide_legend()) +
    ggtitle("Global Pet Ownership")

ggplot(pets) +
    geom_point(aes(x=millions, y=country, colour=pet)) +
    ggtitle("Global Pet Ownership")

PART I
Text Mappings

ggplot(pets) +
    geom_col(aes(x=millions, y=country, fill=pet), position="dodge")

ggplot(pets) +
    geom_vline(aes(xintercept=x), data=data.frame(x=seq(0, 80, 20))) +
    geom_text(aes(label=x, x=x), y=-Inf, vjust=1,
              data=data.frame(x=seq(0, 80, 20))) +
    geom_col(aes(x=millions, y=country, fill=pet), position="dodge")

PART II
CRAP Mappings

CRAP Design

CRAP Data Visualisation

Contrast

Contrast

Repetition

Alignment

Alignment

Alignment

Proximity

Proximity

CRAP mappings

CRAP mappings

Summary

  • There are more mappings (and fewer guides) in a {ggplot2} plot than you might have thought.
  • Mapping data values to text is an important mapping.
  • Mapping metadata to text is an important mapping.
  • Consistency in mappings is important.
  • Mapping structure and importance are important mappings.

Acknowledgements

  • “The Grammar of Graphics” (2nd Edition)
    Leland Wilkinson
  • “The Non-Designer’s Design Book” (4th Edition)
    Robin Williams
  • healthforanimals.org

Questions

  • What does this have to do with R Graphics and {grid}?