ggplot Extensions

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: The Glamour of Graphics

📖 Required Reading: Colors and Palettes

📖 Required Reading: Themes

Extra Resouces

Check-in: Extending ggplot

1. Which of the functions below would you use to change the colors of the bars on the following plot?

  • scale_color_continuous()
  • scale_color_discrete()
  • scale_fill_continuous()
  • scale_fill_discrete()

2. 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?

3. Which built-in theme is each of the following plots? That is, what theme_XXXX() function would produce the added change?

4. Which of the plots above (a, b, c, or d) best adheres to the principles outlined by Will Chase (in the Glamour of Graphics)?

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 Quarto, so that you don’t re-render the images every time you knit your file.

📖 Required Reading: Intro to gganimate

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: More ggplot Extension Summaries

Check-in: Extending ggplot

6. 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?

Extra Resources