Pat creates a visualization showing the polling bias from the 2024 US presidential election using ggplot2 in R as a scatter plot with the x, y, color, fill, size, and alpha aesthetics to highlight the difference in polling and actual vote count, number of electoral votes, number of polls, age of the polls, and whether the data were from a battle ground state. This is his attempt to improve upon a colored barbell plot made by Nate Silver. To pull off this visualization, Pat uses the ggplot2, ggtext, and glue R packages. In addition to geom_point, he uses the geom_abline, annotate, scale_fill_gradient, scale_color_manual, scale_x_continuous, scale_y_continuous, labs, coord_equal, theme_classic, and theme functions. He also used the read_csv, mutate, select, glue, and drop_na functions from the readr, dplyr, and glue packages. You can find the data and code he developed in this episode at https://www.riffomonas.org/code_club/2025-01-02-polling-scatter. Nate Silver's newsletter can be found at https://www.natesilver.net/p/hopium-comes-at-a-high-price. Pat's newsletter describing how he would go about generating the figure can be found at https://shop.riffomonas.org/posts/visualizing-bias-in-polling-data-with-a-dumbbell-plot.
If you have a figure that you would like to see me discuss in a future newsletter and episode of Code Club, email me at [email protected]!
Want more practice on the concepts covered in Code Club? You can sign up for my weekly newsletter at https://shop.riffomonas.org/youtube to get practice problems, tips, and insights. If you're interested in purchasing a video workshop be sure to check out https://riffomonas.org/workshops/
Support Riffomonas by becoming a Patreon member!
https://www.patreon.com/riffomonas
You can also find complete tutorials for learning R with the tidyverse using...
Microbial ecology data: https://www.riffomonas.org/minimalR/
General data: https://www.riffomonas.org/generalR/
If you want to cite this video, please consider citing https://journals.asm.org/doi/10.1128/mra.01310-22
0:00 Introduction
8:38 Generating scatter/bubble plot
13:01 Representing age of data with alpha
17:10 Representing number of electoral votes with fill
17:48 Representing battleground states with color
19:37 Adjusting bulk appearance of figure
20:03 Modifying appearance of alpha and fill
24:51 Modifying appearance of stroke color
25:54 Modifying titles and labels
41:41 Adding interpretative keys to corners