Week 2: ggplot Extensions

Stat 431



Time Estimates:
     Videos: 21 min
     Readings: 30 min
     Activities: 60 min
     Check-ins: 5



Extra Resources:

Custom Colors and Themes

A huge part of making a compelling and convincing plot is your choice of color and layout.

Your first video will take you through some great core principals of visualization. Then your two short readings will show you the basics of manipulating colors and themes in ggplot.


Required Video: What makes a nice-looking graphic?

The Glamour of Graphics - William Chase

Or, if you prefer to click through the slides, they are here.


Required Reading: Colors and Palettes



Required Reading: Themes



Extra Resources:

Check-In 1: Custom Colors


  1. Briefly explain the difference between:
  • scale_color_continuous()
  • scale_color_discrete()
  • scale_fill_continuous()
  • scale_fill_discrete()
  1. Which of the above would you use to change the colors of the bars on the following plot?

Canvas Link     


Check-In 2: Theme settings


Consider the plot in Question 1. What change was made to it in each step below? That is, what code would go inside the function + theme( ) to produce the added change?


Check-In 3: Full Themes


Which built-in theme is each of the following plots?

Canvas Link     

gganimate

There are many, many ways to “spice up” your plots. We will focus in on one: making your plot animated!

The best package for this, if you are using ggplot already, is gganimate.

Note: gganimate plot objects can sometimes take a long time to render. One way to make it quicker is to change the number of frames in your gif. Another trick is to use the cache chunk option in R Markdown, so that you don’t re-render the images every time you knit your file.


Required Reading: Intro to gganimate



Recommended Reading: Another intro to gganimate



Optional Video: gganimate flipbook demo (RStudio::conf 2017)



Just for fun: Dave Robinson debuts gganimate at PlotCon 2016

Check-In 4: gganimate


Fill in the blanks for the following two gganimate plots

   <- oscars %>%
  filter(Award_Gender != "Ungendered") %>%
  ggplot(aes(y = Age_at_Award, x = award, fill = Award_Gender)) +
  geom_boxplot() +
  ggtitle("Age of Academy Award Winners ({             })") +
  xlab("Year of Award") +
  ylab("Age at Award") +
  transition_      (Award_Gender) +
             (alpha = 0.3)

animate(p1,        = 10,    = 5)

   <- oscars %>%
  filter(Award_Gender != "Ungendered") %>%
  ggplot(aes(x = Age_at_Award, fill = Award_Gender)) +
  geom_density(alpha = 0.5) +
  ggtitle("Age of Academy Award Winners ({          }s)") +
  xlab("Year of Award") +
  ylab("Age at Award") +
                 (Decade_of_Award)

animate(p2,        = 9,    = 1)

Canvas Link     

Other Extensions

Although we don’t have time to go in-depth on every single extension of ggplot, there are so many wonderful ways to up your Data Viz game.

Take a look around the links below.


Required Reading: ggplot extension gallery



Required Reading: more ggplot extension summaries



Check-In 5: More Extensions


Which extension package would you use to… Hint: There is more than one possible answer for each question!

  1. Visualize a social network using twitter data?
  1. Add p-values to your side-by-side boxplot of treatment groups, showing the significance of the differences?
  1. Arrange several different plots next to each other?
  1. Make it so hovering over a point in your scatterplot shows the corresponding label?

Canvas Link