`ggplot2`

After going over the course syllabus, we’ll go over the following three lessons:

- Orientation to statistical graphics
- The grammar of graphics
- Plotting with
`x`

and`y`

aesthetics

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:

- Jenny’s ggplot2 tutorial.
- Has a lot of examples, but less dialogue.

- R Graphics Cookbook
- Good as a reference if you want to learn how to make a specific type of plot.

`ggplot2`

cheatsheet

To get participation points for today:

- Fill out this exercise sheet with me in class.
`git commit`

whatever we finish in class to your participation repository.

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 (not on quiz) - Have a sense of the importance of statistical graphics in communicating information

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

- base R
`lattice`

`ggplot2`

- Part of the
`tidyverse`

- Part of the
`plotly`

`ggplot2`

will receive the strongest focus in this course. Why?

- 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.

Jenny Bryan on statistical graphics:

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

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
- You’ll later be expected to be able to explain the main idea behind the components.

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

`x`

and `y`

aestheticsThis 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

Let’s fill out as much as we can of the worksheet labelled `lec1-worksheet.Rmd`

.