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.

Introduction

Write a brief introduction about the data being plotted, including the information

  1. who collected it,
  2. how it was collected,
  3. why the process was repeated in 2016

This should be about 4-5 sentences.

Create data

Create vectors to contain the data and labels to make the pie graphs at the top of figures.

Each vector has 3 elements: European ancestry, Asian ancestry, and other non-European ancestry.

DO NOT name your vector for the labels “labels”, since this is the name of an existing R function.

Include new line characters in the text as needed to improve spacing.

euro_non_euro09<-c(96,4)
labels09<-c('European Ancestry','Non-European Ancestry')
euro_non_euro16<-c(81,14,5)
labels16<-c('European ancestry', 'Asian' , 'Other non-European')
colo = c('black', 'light blue', 'blue')

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.)

Pie graphs

  1. Set the argument radius = … to 1. Experiment with how this affects the plot.
  2. Set the argument col = … to c(1,2,3), then experiment with different numbers. Try to make it ugly.
# set up par()
par(mfrow = c(3,2), mar = c(2,2,2,2))

#pie graphs 1
# add main, init.angle, radius, and col
sum(euro_non_euro09)
## [1] 100
pie(x = euro_non_euro09, 
    labels = labels09,
    main = 'Ancestry data in 2009',
    init.angle = -83,
    col = colo)

# pie graph 2
# add main, init.angle, radius, and col
sum(euro_non_euro16)
## [1] 100
pie(x = euro_non_euro16, 
    labels = labels16,
    main = 'Ancestry data in 2016',
    init.angle = -55,
    radius = 1,
    col = colo)

Bar graphs

If you want, you can examine this code below to see how stracked 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)