7 More ggplot2

Author

Matt Crump

Published

January 23, 2023

We are going to skip the next chapter in the book and spend more time on ggplot2 for making graphs.

The ggplot2 package is extremely deep and powerful. We will become more familiar with its capabilities by working through multiple examples, and then attempting to reproduce existing figures published in journals.

More basic plotting examples

This page provides examples of scatterplots, line graphs, and bar graphs including error bars.

More ggplot examples

Graph Reproduction exercise

The challenge for this week is to attempt to reproduce existing graphs using ggplot2. The first page contains example graphs that were published in Psychological Science. The data used to create these graphs is NOT provided. The exercise is to look at the graph, then create the data that you would need in order to reproduce the graph with ggplot, and finally reproduce the graph with ggplot.

Graphs from Psychological Science to reproduce

Here are some example solutions for the first several graphs.

Example solutions

Additional resources

ggplot2 additional resources

Add-on packages

  • https://www.ggplot2-exts.org A repository of 50+ add on packages for ggplot2
  • https://gganimate.com
  • ggrepel allows you to repel overlapping text labels away from each other.
  • esquisse a GUI (graphic user interface) that allows you make ggplot graphs using drag-drop, and clickable options
  • ggedit similar to above, clickable editing of ggplot graphs
  • plotly a package similar to ggplot, makes a whole variety of graphs, mainly for use in websites. Allows interactive graphs.
  • ggpubr (install from CRAN), many useful things, including the ggarrange function which allows you to knit multiple plots together
  • ggthemes extra themes, scales, and geoms

Week 7 assignment

  1. Write your blog post, and submit the link to this assignment on blackboard. Blog post ideas will be discussed in class, and this assignment will be updated for clarity.
  • be able to make a scatterplot between an x an y variable
  • be able to make a line graph with points
  • be able to make a bar graph
  • be able to make a bar graph with error bars
  • attempt to reproduce as many figures from the examples as possible.