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 pie graphs below are comparing the distribution of three different ancestries being used when conducting a Genome Wide Association Study (GWAS),between the years 2009 and 2016. The data was first collected and analysed by Alice B. Popejoy and Stephanie M.Fullerton, through the use of GWAS in 2009. It was then repeated in 2016 to determine if there had been a percentage difference in the inclusion of varying ancestries in genome studies. This data is important as it is outlining deficiencies in larger ancestry data and trying to make associations about certain acnestries being susceptible to disease.
This code chunk is creating the basic pie charts encapsulating the data from the study and labelling them with the correct ancestry group name.
euro_noneuro_asian2016 <- c(81,19,14)
title1 <- c("European Ancestry\n",
"Other non-European Ancenstry\n",
"Asian Ancestry\n")
sum(euro_noneuro_asian2016)
## [1] 114
pie(x = euro_noneuro_asian2016,
labels = title1 )
euro_noneuro_asian2009 <- c(96,4,3)
title2 <- c("European Ancestry\n",
"Other non-European Ancenstry\n",
"Asian Ancestry\n")
sum(euro_noneuro_asian2009)
## [1] 103
pie(x = euro_noneuro_asian2009,
labels = title2)
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.)
This code chunk is altering the parameters of the pie charts, including adding titles, angles, radius and colours.
# set up par()
par(mfrow = c(1,2), mar = c(2,3,1,5))
pie(x = euro_noneuro_asian2016,
labels = title1,
main = "2016",
init.angle = -82,
radius = 1,
col = c(1,2,3))
#pie graphs 1
# add main, init.angle, radius, and col
# pie graph 2
# add main, init.angle, radius, and col
pie(x = euro_noneuro_asian2009,
labels = title2,
main = "2009",
init.angle = -82,
radius = 1,
col = c(1,2,3))
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)