Announcement

Building Graphics

  1. Draw (by hand) or imagine the specific plot that you intend to construct
  2. Data Wrangling (if needed) - get the data in glyph-ready form, or verify that the current form is glyph-ready for your purposes.
  3. Establish the frame using a ggplot() statement
  4. Create the intended glyph using geom_[style]() such as
    • geom_point()
    • geom_bar()
    • geom_boxplot()
    • geom_density()
    • geom_vline()
    • geom_segment()
    • geom_histogram()
    • geom_ash()
    • and many more
  5. Map variables to the graphical attributes of the glyph using aes( )
  6. Add additional layers to the frame using the + symbol

Want some help?

This can all be a lot to keep straight… visit “Canvas >> Files >> Cheatsheets”" for some resources to help you shoulder the burden:

Also see…

Remarks about facet_wrap()

The syntax for facets can be a bit complicated for new users. Here are a few pointers:

data("NCHS")

# 1is.na(smoker) gets cases that are non-missing for `smoker` (i.e. removes NA's)
Heights <- 
  NCHS %>%
  filter(age > 20, !is.na(smoker)) %>%   
  group_by(sex, smoker, age) %>%
  summarise(height = mean(height, na.rm = TRUE))

Heights %>%
  ggplot(aes(x = age, y = height)) + 
  geom_line(aes(linetype = smoker)) + 
  facet_wrap( ~ sex)

Remarks about facet_grid()

Heights %>%
  ggplot(aes(x = age, y = height)) + 
  geom_line(aes(linetype = smoker)) + 
  facet_grid(sex ~ .)

Heights %>%
  ggplot(aes(x = age, y = height)) + 
  geom_line() + 
  facet_grid(sex ~ smoker)

Homework

Activity: Bicycle Sharing (DC p. 182)

Assignment is worth a total of 10 points.


teaching | stat 184 home | syllabus | piazza | canvas