Assignment information: (delete this when you submit) In this assignment you will re-build the pie graphs shown in the paper “Genomics is failing on diversity” by Popejoy and Fullerton (https://www.nature.com/articles/538161a). Delete all instructions and replace with short explanatory text about all code chunks. Be sure to change the title in the YAML header.
If possible, save this file to your Teams folder.
The data being plotted is from a study by authors Alice Popejoy and Stephanie Fullerton. This is a recreation from a study done in 2009 that analyzed sample descriptions from GWAS. In 2016, this study was repeated to see how the proportions of people change. The scientists found that there are a lot less participants of european heritage in 2016 compared to 2009.
1 vector is created for 2009 and the other for 2016. Another vector is made for the ancestry labels for the pie graph.
ancestry2009 <- c(96, 3, 1)
ancestry2016 <- c(81, 14, 5)
ancestry_labels <- c("European", "Asian", "Other")
Pro Tip: adding a new line character in front of the text or behind it in your labels and help you adjust spacing. E.g. “European” or “” (note - if you don’t delete this instruction the preceding text will have some weird features.)
# set up par()
par(mfrow = c(1,2), mar = c(2,3,1,5))
#pie graphs 1
# add main, init.angle, radius, and col
pie(x = ancestry2009, labels = ancestry_labels, main = "2009", init.angle = -82, radius = 1, col = c(1, 2, 3))
# pie graph 2
# add main, init.angle, radius, and col
pie(x = ancestry2016, labels = ancestry_labels, main = "2016", init.angle = -82, radius = 1, col = c(1, 2, 3))
If you want, you can examine this code below to see how stacked bar graphs are made
# data
dat2016 <- c(14, 3,1,0.54,0.28,0.08,0.05)
dat2016_rev <- rev(dat2016)
barplotdata2016 <- matrix(c(dat2016_rev))
# labels
labels_x <- rev(c("Asian","African","Mixed", "Hispanic &\nLatin American",
"Pacific Islander","Arab & Middle East","Native peoples"))
par(mfrow = c(1,1))
barplot(barplotdata2016,
width = 0.01,
xlim = c(0,0.1),
axes = F,
col = c(1,2,3,4,5,6,7),
legend.text = labels_x)