03 Coordinate systems and axes

Example: Population of Swedish municipalities

A linear scale emphasizes large counties

Example: Population of Swedish municipalities

A log scale shows symmetry around the median

Nonlinear coordinate systems: Polar coordinates

Cartesian coordinates

Polar coordinates

Cartesian vs polar coordinates

Cartesian coordinates

Polar coordinates

Scales and coordinate systems in ggplot2

Scale functions customize the x and y axes

Recall the musical artists example from a prior lecture

ggplot(artists, 
       aes(monthly_streamers, 
           fct_reorder(artist, monthly_streamers))) +
  geom_col()

Scale functions customize the x and y axes

Add scale functions (no change in figure so far)

ggplot(artists, 
       aes(monthly_streamers, 
           fct_reorder(artist, monthly_streamers))) +
  geom_col() +
  scale_x_continuous() +
  scale_y_discrete()

Scale functions customize the x and y axes

The parameter name sets the axis title

ggplot(artists, 
       aes(monthly_streamers, 
           fct_reorder(artist, monthly_streamers))) +
  geom_col() +
  scale_x_continuous(
    name = "Monthly streamers"
  ) +
  scale_y_discrete(
    name = NULL # no axis title
  )