Fundamentals & Workflows

09:00-10:30

Date

September 18, 2023

View slides in full screen | Run the code yourself

Outline

  • Welcome
  • The {ggplot2} Package
  • The {ggplot2} Showcase
  • A Walk-Through Example
  • Saving Plots
  • Programming with {ggplot2}
  • Combine Plots
  • Exciting Extension Packages
  • Exercises

Recap

  • a basic ggplot is build by specifying three components:
    data, aesthetics and a layer (usually a geom_* or stat_*)
  • aesthetic mappings define how variables map to visual properties
  • the default appearance of all other components can be modified via scale_*, coord_*, facet_* and theme_* / theme
  • use the devices cairo (pdf) and agg (png, jpg, tiff) when saving plots
  • find a suitable plot size by setting figure chunk options in qmd/rmd files or with the help of the {camcorder} package
  • define conditional components, custom layers and functions to generate plots more efficiently and to iterate over multiple inputs
  • combine multiple plot outputs with {patchwork}

Exercises

Exercise 1

  • Discuss / investigate with your neighbor:
    • What are the differences between geom_line() and geom_path()?
    • Why can you use geom_smooth() and stat_smooth() interchangeably?
    • What are the three ways to remove a legend from a ggplot?
    • Which is your favorite theme?
    • What is your favorite ggplot2 extension package?

Exercise 2

  • Explore the TfL bike share data visually:
    • Create a time series of counts per day and night.
    • Draw box and whisker plots of average temperatures per month.
    • Visualize bike counts per weather type and period as bar chart.
  • Combine the three plots with {patchwork}.
  • Export the final graphic in a format of your choice.


Exercise Template | Solution