Skip to content

Plotting

Learning outcomes

  • Comfortable with the first chapter of R for Data Science
  • Can use ggplot2 for simple plots
  • Can create simple ggplots from tidy data
  • Can use some ggplot aesthetics
  • Can use some ggplot geometrical objects
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.

Exercises

Exercise 1

Answers

See the answers here

Note that the answers use chapter 2.2.5.

(optional) Exercise 2

Answers

See the answers here

Note that the answers use chapter 2.4.3.

(optional) Exercise 3

Answers

See the answers here

Note that the answers use chapter 2.5.5.

(optional) Exercise 4

Answers

See the answers here

Note that the answers use chapter 2.6.1.