## 0.1 Announcements

• No break today.

## 0.2 Today’s Lessons

Today’s lessons are:

• Orientation to statistical graphics
• The grammar of graphics
• Plotting with x and y aesthetics

## 0.3 Resources

Concepts from today’s class (and next class) are closely mirrored by the following resources, which introduce ggplot2, although are organized in different ways for each.

The following are good walk-throughs that introduce ggplot2:

• r4ds: data-vis chapter.
• Perhaps the most compact “walk-through” style resource.
• The ggplot2 book, Chapter 2.
• A bit more comprehensive “walk-through” style resource.
• Section 1.2 introduces the actual grammar components.

Here are some other resources you might find useful:

## 0.4 Participation

To get participation points for today, we’ll be filling out the cm006-exercise.Rmd file, and adding it to your participation repo.

Let’s get set up:

1. To download the file the easy way, just click the upper-right drop-down menu of the html version of the file.
2. Download the .Rmd version to your local participation repo.
3. Open the .Rmd file, and change the output type to html_document, keeping the .md file, too.
4. Optional, but recommended: Stage and commit the Rmd file (you can do this through RStudio).
• You can still get participation marks by uploading the final files to GitHub.

# 1 Orientation to statistical graphics

## 1.1 Learning Objectives

By the end of this lesson, students are expected to be able to:

• Identify the plotting framework available in R
• Have a sense of why we’re learning the ggplot2 tool
• Have a sense of the importance of statistical graphics in communicating information

## 1.2 Discussion

There are three main ways you can produce graphics in R. In order of inception, they are

• base R
• lattice (an R package)
• ggplot2 (an R package)
• Part of the tidyverse

Why ggplot2?

• once fluent, can make most plots up to publication quality standard very quickly.
• has theoretical underpinning in the “layered grammar of graphics”, which is described in the book by Leland Wilkinson.

Stackoverflow was my main source of learning. Google what you’re trying to do, and persevere. You can do it.

• A picture is worth 1000 words
• More philosophy on graphics
• Comparing base R/lattice/ggplot2
• The learning curve

# 2 The grammar of graphics

## 2.1 Learning Objectives

By the end of this lesson, students are expected to be able to:

• Identify the seven components of the grammar of graphics underlying ggplot2
• Have a sense of what the seven components are

## 2.2 Discussion

Leland Wilkinson lays out the grammar of graphics in his book.

They define the “space of statistical graphics”.

The grammar components, adapted to ggplot2 (gg = grammar of graphics), where the bold ones are necessary to specify for every plot:

• Data
• Aesthetic mappings
• Geometric objects
• Scales
• Statistical transformations
• Coordinate system
• Facet specification

# 3 Plotting with x and y aesthetics

## 3.1 Learning Objectives

This live-coding-based lesson focusses on:

• using the x and y aesthetic mappings, while
• using different geometric objects to explore various plot “types”.

By the end of this lesson, students are expected to be able to:

• Create a variety of “plot types” using ggplot2 under the following situations:
• two numeric variables
• one numeric variable
• one numeric, one categorical variable

## 3.2 Demonstration

Note: We’ll be jumping straight into the ggplot() function, instead of the more limited qplot() function.

Follow along with the cm006-exercise.Rmd file we downloaded earlier.