MENU

Fun & Interesting

How to draw braces to annotate a bar plot in R using ggplot2 (CC346)

Riffomonas Project 709 lượt xem 1 month ago
Video Not Working? Fix It Now

Pat uses R to show how to create braces that are used to annotate dodged bar plots in order to recreate an iconic bar plot figure that WEB DuBois presented at the 1900 Paris Exposition showing the age distribution of Black Georgians relative to the French population using the ggplot2, dplyr, and showtext packages. The functions he uses from these packages include aes, case_when, coord_cartesian, cos, element_blank, element_text, factor, font_add, function, geom_col, geom_path, geom_text, ggplot, ggsave, labs, library, map, margin, paste0, pivot_longer, position_dodge, rev, scale_color_manual, scale_fill_manual, seq, showtext_auto, showtext_opts, sin, theme, tibble, tribble, unit, and unnest. You can find the data and code he developed in this episode at https://www.riffomonas.org/code_club/2025-03-03-plate-09. Pat described his strategy for this figure in his newsletter at https://shop.riffomonas.org/posts/em-bracing-ggplot2-to-recreate-historic-data-visualizations. The book Pat mentions by Whitney Battle-Baptiste and Britt Rusert, titled "W.E.B. Du Bois's Data Portraits: Visualizing Black America" is available at https://amzn.to/4heJOWZ. A great set of talks about the DuBois data portraits is available at https://www.youtube.com/watch?v=ZZST1AZj-dQ&ab_channel=Tableau. The Anthony Starks GitHub repository can be found at https://github.com/ajstarks/dubois-data-portraits/. 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 pat@riffomonas.org!

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
6:46 Creating a dodged bar chart
13:28 Adding percentages to bar plot
21:32 Experimenting with drawing braces
31:59 Adding braces to bar plot
38:54 Cleaning up appearance to match DuBois

Comment