MENU

Fun & Interesting

How to extract data from a heatmap with R using the tidyverse (CC348)

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

Pat uses R to show how to extract the underlying data from a heatmap published in the New York Times describing the increase in deaths among Black men in Chicago due to drug overdoses. To pull this off he uses the ggplot2, dplyr, scales, and png packages. The functions he uses from these packages include as.character, as.numeric, as_tibble, col2rgb, cut, filter, function, group_by, library, map, matrix, mean, mutate, names, ncol, nrow, pal_gradient_n, pivot_longer, readPNG, rgb, select, slice_min, sqrt, str_detect, str_replace, summarize, t, table, tibble, unnest, which.max, and write_tsv. You can find the data and code he developed in this episode at https://www.riffomonas.org/code_club/2025-03-10-fentanyl-extract. You can find the original New York Times article at https://www.nytimes.com/2025/01/30/upshot/black-men-overdose-deaths.html. 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:20 Extracting content of PNG file into R
19:15 Isolating heatmap from rest of image
23:09 Getting RGB hexcode for each tile in heatmap
37:40 Creating standard curve
46:55 Applying standard curve to extract n

Comment