The dot plots below represent the ancestry of participants in Genome-wide association studies (GWAS) in both 2009 and 2016. As you can see, the majority of participants come from a European ancestry. The 2009 percentage has dropped when compared to the 2016 percentage while the percentage of participants of Asian ancestry has risen, however there is still much more progress to be made. The writers of “Genomics is failing on diversity” analysed nearly 35 million sample descriptions included in the GWAS catalog to determine the ancestry of participants. This was conducted in 2009 and 2016 to analyse the difference in diversity over time.
The code chunk below creates 4 vectors, two for each pie chart. For the first pie chart, vector_2009 was created with the percentage being represented for each ancestry. label1 was then created to show which ancestry the percentages refer to. The same logic was used with the creation of vector_2016 and label2.
Vector_2009 <- c(96, 3, 1)
label1 <- c("European", "Asian", "Other")
vector_2016 <- c(81, 14, 5)
label2 <- c("European", "Asian", "Other")
The below code line uses the par command to create a 1 X 2 grid. Two pie charts are then plotted, one for the 2009 and 2016 vectors created above. The arguments used for creating the pie charts are init.angle = -82, radius = 1, and col = c(1, 2, 3). Titles were also given to each graph using the main argument with new line characters being used for formatting.
# 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(Vector_2009, labels = label1, main = "\nAncestry of GWAS \nParticipants in 2009", init.angle = -82, radius = 1, col = c(1, 2, 3))
# pie graph 2
# add main, init.angle, radius, and col
pie(vector_2016, labels = label2, main = "\nAncestry of GWAS \nParticipants in 2016", init.angle = -82, radius = 1, col = c(1, 2, 3))
The below code chunck shows how to properly create a stacked bar graph.
# 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)