Pat uses R to show how to recreate a stacked bar plot posted by the Pew Research Center describing people's sense of how different groups will fare under the Trump Administration. To pull this off he uses the ggplot2, showtext, and ggtext packages. The functions he uses from these packages include aes, coord_cartesian, element_blank, element_markdown, element_text, facet_grid, factor, font_add_google, geom_col, geom_text, ggplot, ggsave, labs, library, margin, mutate, pivot_longer, position_stack, rev, scale_fill_manual, showtext_auto, showtext_opts, theme, tribble, and unit. The newsletter describing this visualization at a 30,000 ft view can be found at https://shop.riffomonas.org/posts/my-second-least-favorite-data-visualization-type. You can find the data he uses and the code he developed in this episode at https://www.riffomonas.org/code_club/2025-03-17-pew1. You can find the original Pew Research Center article at https://www.pewresearch.org/short-reads/2025/02/28/americans-expect-corporations-the-wealthy-white-people-and-other-groups-to-gain-influence-under-trump/. 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:07 Creating a labelled stacked bar plot
12:13 Separating groups using facets
16:46 Using factors to order the variables
21:05 Picking colors and formatting the legend
25:07 Formatting the axes and facets
27:52 Adding and formatting the titles and caption
34:20 Adjusting the margins and spacing