From 3f5a9933e5ba23e718739f69e5c3a444e9d7ca65 Mon Sep 17 00:00:00 2001 From: ritafonso <88333601+ritafonso@users.noreply.github.com> Date: Wed, 1 Dec 2021 12:11:52 +0000 Subject: [PATCH] Update snp_pca_static.R Plot pairwise PCA with four vectors, instead of two. Plot a barplot with the first 6 eigen values. Combined both plots in the same file. --- snp_pca_static.R | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/snp_pca_static.R b/snp_pca_static.R index 2d988eb..aab5e57 100755 --- a/snp_pca_static.R +++ b/snp_pca_static.R @@ -74,3 +74,38 @@ if (!is.na(pops_file)) { file.remove("temp.gds") dev.off() + +##create matrix with pairwise euclidean distance +mat <- dist(tab, method="euclidean", diag = F, upper =F, p=2) +distance_matrix <- as.matrix(dist(mat)) +write.table(distance_matrix, file = "pairwise_distance_matrix.txt", sep = "\t", row.names = TRUE, col.names = NA) + +#list first 6 eigen values +head_eigen <- as.data.frame(head(round(pc.percent, 2))) +head_eigen$index <- c("1","2","3","4","5","6") +colnames(head_eigen) <- c("varexp","pcindex") + +#combined plot - paiwise pca + eigen values plot +library(pryr) +library(grid) +png(paste("pca_combined_plot", ".png", sep="")) + #plot pairwise pca using the first four vectors +p1 %