R Community of Practice

Week 3

Learning Goals

  1. Become familiar with the basic components of a ggplot2 graph
  2. Understand the concept of “aesthetic mapping”
  3. Use ggplot2 to create bar graphs
  4. Use ggplot2 to customize graphs

The Data

Scenario: We want to visualize the all_workshops data frame we created in Week 1.

We’ll complete the following tasks:

  1. Create a basic bar chart comparing workshop attendance among the various schools.
  2. Create a grouped bar chart comparing workshop attendance among the schools and university roles.
  3. Add titles and labels to our graph
  4. Adjust the color palette
  5. Choose a theme
  6. Output graph to jpeg file

ggplot2 Basics

The “gg” in ggplot2 refers to the “grammar of graphics”.

All ggplot2 graphs start with the same basic template:

<DATA> %>%
    ggplot(aes(<MAPPINGS>)) +
    <GEOM_FUNCTION>() +
    <Additional GEOMS, SCALES, THEMES, etc. . . >

Helpful Resources