MENU

Fun & Interesting

Using ggplot2 to visualize relationship between life expectancy and health spending in R (CC338)

Riffomonas Project 1,157 1 week ago
Video Not Working? Fix It Now

Pat recreates a figure from The Times showing the change in life expectancy by the amount of health care spending for seven countries using tools from R's dplyr, ggplot2, showtext, and ggtext. The functions he uses from these packages include aes, annotate, arrange, coord_cartesian, element_blank, element_line, element_markdown, element_rect, element_text, factor, format, geom_point, geom_text, ggplot, ggsave, labs, margin, mutate, read_tsv, scale_color_manual, scale_fill_manual, scale_size_continuous, scale_x_continuous, scale_y_continuous, select, seq, theme, and tribble. You can find the data and code he developed in this episode at https://www.riffomonas.org/code_club/2025-02-03-health-expenditure. The original Times news article is available at: https://www.thetimes.com/comment/columnists/article/we-keep-pumping-money-into-the-nhs-is-it-good-value-blq8bxc39. Pat's newsletter describing how he would go about generating the figure can be found at https://shop.riffomonas.org/posts/representing-time-in-a-bubble-plot-with-ggplot2. The csv file can be downloaded from https://datawrapper.dwcdn.net/Bxhol/9/dataset.csv. 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 3:58 Construct bubble plot 21:03 Label and format x and y axes 28:09 Add titles and captions to plot 40:03 Add axis, country, and year labels

Comment