Position adjustments and coordinate systems

STAT1003 – Statistical Techniques

Dr. Emi Tanaka

Australian National University

These slides are best viewed on a modern browser like Google Chrome on a desktop or laptop. Some interactive components may require some time to fully load.

Visualising amounts and proportions

  • geom_bar()
  • geom_col()
  • geom_point()
  • geom_tile()
  • geom_density()

A barplot with geom_bar()

  • Here the stat = "count" is computing the frequencies for each category for you.
  • You can alternatively use stat_count() and change the geom.

Summary data

  • Sometimes your input data may already contain pre-computed counts.
  • What is the observational unit (row) for the datasets below?

A barplot with geom_col()

  • In this case, you don’t need stat = "count" to do the counting for you and use geom_col() instead.
  • This is essential a short hand for geom_bar(stat = "identity") where stat = "identity" means that you will take the value as supplied without any statistical transformation.

Position adjustments in barplots

Position adjustments

  • position_dodge() for grouped barplots
  • position_dodge2() for improved grouped barplots
  • position_fill() for stacked percentage barplots
  • position_identity() to use the raw positions
  • position_jitter() to add random noise to points
  • position_jitterdodge() for jittered and dodged points
  • position_nudge() to shift the position by a fixed amount
  • position_stack() for stacked barplots

Pie or donut charts with coord_polar()

  • The default coordinate system is the Cartesian coordinate system.
  • But you can change this to a polar coordinate system like below.

Coordinate systems

  • coord_cartesian() for Cartesian coordinate systems (default)
  • coord_equal() is essentially coord_fixed(ratio = 1)
  • coord_fixed() to use a fixed aspect ratio
  • coord_flip() to flip the x and y
  • coord_map() to use projection based on mapproj
  • coord_munch() to improve rendering of large datasets
  • coord_polar() to use polar coordinates
  • coord_quickmap() for quick map coordinate system
  • coord_radial() for radial coordinates
  • coord_sf() for spatial data frames
  • coord_transform() to transform the coordinate after the statistical transformation

Summary

  • position_dodge()
  • position_dodge2()
  • position_fill()
  • position_identity()
  • position_jitter()
  • position_jitterdodge()
  • position_nudge()
  • position_stack()
  • coord_cartesian()
  • coord_equal()
  • coord_fixed()
  • coord_flip()
  • coord_map()
  • coord_munch()
  • coord_polar()
  • coord_quickmap()
  • coord_radial()
  • coord_sf()
  • coord_transform()