# load package adegenet – need to do from GUI drop-down menu# # load genetic data in genepop format, then corresponding XY data as a table# obj <- read.genepop (file.choose(), missing=0) obj@other$xy <- read.table (file.choose(), header = T) # convert individual-based data to population-based# obj2 <- genind2genpop(obj,pop=NULL,missing="NA",quiet=FALSE,process.other=TRUE, other.action=mean) # perform SPCA# spca <- spca (obj2, xy=obj2@other$xy) # test significance of global pattern, view and plot# myGtest <- global.rtest(obj2$tab, spca$lw, nperm = 999) myGtest plot(myGtest) # test significance of local pattern, view and plot # myLtest<- local.rtest(obj2$tab, spca$lw, nperm = 999) myLtest plot(myLtest) # plot tri-color map of spca scores – combines up to 3 scores# colorplot(spca, cex=5, main="SPCA Scores") #plots by SPCA axis# # plot spca results – network, gradient, pca scores, eigen values, eigen graph for PCA 1# plot(spca) # plot contributions of each allele to PCA 1# Loadings1 <- spca$c1[, 1]^2 names(Loadings1) <- rownames(spca$c1) loadingplot(Loadings1, xlab="Alleles", ylab="Wieghts", main="Allele Contributions to PCA 1") # plot contributions of each locus to PCA 1# boxplot(Loadings1 ~ obj2$loc.fac, las = 3, main = "Locus Contributions to PCA 1") # plot spca results – network, gradient, pca scores, eigen values, eigen graph for PCA 2# plot(spca, axis=2) # plot contributions of each allele to PCA 1# Loadings2 <- spca$c1[, 2]^2 names(Loadings2) <- rownames(spca$c1) loadingplot(Loadings2, xlab="Alleles", ylab="Wieghts", main="Allele Contributions to PCA 2") # plot contributions of each locus to PCA 1# boxplot(Loadings2 ~ obj2$loc.fac, las = 3, main = "Locus Contributions to PCA 2") # call up PCA scores for all saved axes# spca$li # call up PCA lags for all saved axes# spca$ls