Skip to content

Plotting

Learning outcomes

  • I am comfortable with the first chapter of R for Data Science
  • I can use ggplot2 to create a simple plot
  • I can save a plot created by ggplot2
  • I can tell what ggplot2 aesthetics are
  • I can tell what ggplot2 geometrical objects are
For teachers

Teaching goals are:

  • Learners have read part of the first chapter of R for Data Science
  • Learners have created simple plots in ggplot2
  • Learners can create simple ggplots from tidy data
  • Learners can set the aesthetics x, y and color
  • Learners can use geom_scatter, geom_boxplot and geom_smooth for simple aesthetics

Prior question:

  • What is the most used use R package for plotting?
  • What is gg in ggplot2?
  • What is tidy data?
  • There is a philosophy that 'missing values should never silently go missing'. What does that mean?

Feedback questions:

  • What is gg in ggplot2?
  • What is tidy data?
  • What is an aesthetic?
  • What is a geom?
  • The philosophy that 'missing values should never silently go missing'. What does this mean?

Why ggplot2 is important

The ggplot2 logo

ggplot2 allows you to create publication-quality graphs for your paper, using a unified (and extensible) grammar, which allows you to express your unique plotting needs.

Additionally, ggplot2 is the CRAN package with the most downloads per month.

Exercises

Exercise 1: your first ggplot2 plots

Answers

See the answers here

Note that the answers use chapter 2.2.5.

Exercise 2: saving your plots

Answers

See the answers here

Note that the answers use chapter 2.6.1.

(optional) Exercise 3: different type of data, different type of plot

Answers

See the answers here

Note that the answers use chapter 2.4.3.

(optional) Exercise 4: expressing relations in color, fill and facets

Answers

See the answers here

Note that the answers use chapter 2.5.5.