In RStudio: pcs = read.table( "chr19-clean.eigenvec" ) View(pcs) plot( pcs[,3], pcs[,4], xlab = "PC1", ylab = "PC2" ) Q. What do you see? Is there any obvious structure in the dataset? We might also want to plot more than just the top two PCs. Let's plot all pairs of the top 5 PCs: In RStudio: colnames(pcs)[3:7] = c( "PC1","PC2","PC3","PC4","PC5" ) pairs( pcs[, 3:7] ) Hint: In Rstudio, you can click the 'zoom' button above above the plot to get a bigger version. Our dataset contains samples with different ethnicities that in our dataset are recorded in the first column of the file (plink calls this a 'family ID' but here we've used it to record sampled ethnicities). Make a list of them using table(): pcs[,1] ) Different ethnic groups might be genetically distinct, so they might separate on the PCs. Let's replot colouring points by their ethnicity. We'll do this in three steps Turn ethnicities into integers that we can pass to the argument of col plot(). Plot using the colours Add a legend to the plot so we can see what is what. (The and arguments below are used to tweak the lower.panel xpd appearance of the plot and how the legend is plotted. See and if ?pairs ?par you want more information, but don't worry about these for now.) In RStudio:
In RStudio: pcs = read.table( "chr19-clean.eigenvec" ) View(pcs) plot( pcs[,3], pcs[,4], xlab = "PC1", ylab = "PC2" ) Q. What do you see? Is there any obvious structure in the dataset? We might also want to plot more than just the top two PCs. Let's plot all pairs of the top 5 PCs: In RStudio: colnames(pcs)[3:7] = c( "PC1","PC2","PC3","PC4","PC5" ) pairs( pcs[, 3:7] ) Hint: In Rstudio, you can click the 'zoom' button above above the plot to get a bigger version. Our dataset contains samples with different ethnicities that in our dataset are recorded in the first column of the file (plink calls this a 'family ID' but here we've used it to record sampled ethnicities). Make a list of them using table(): pcs[,1] ) Different ethnic groups might be genetically distinct, so they might separate on the PCs. Let's replot colouring points by their ethnicity. We'll do this in three steps Turn ethnicities into integers that we can pass to the col argument of plot(). Plot using the colours Add a legend to the plot so we can see what is what. (The lower.panel and xpd arguments below are used to tweak the appearance of the plot and how the legend is plotted. See ?pairs and ?par if you want more information, but don't worry about these for now.) In RStudio: