[Fig 4 below is what I would need as outcome, the other 2 figures show what I get from my data: PCA on environmental data or on the abundance data
No duplication ofR - how to make PCA biplot more readable or Plotting pca biplot with ggplot2
It is conducting abundance and environmental data in PCA simultaneously, working with two different data frames: I was told it shall work in the way, that from PCA1 you get the coordinates for the species and than with a second command you overlay over the species coordinates vectors not from PCA 1 but from another dataset that has the same sites as the first one not abundance but environmental data.
My prof did a PCA on abundance and environmental data 10 years ago. He overlaid the results of the principal components analysis (PCA) of abundance data of species with the correlations between the PCA scores and the environmental factors potentially influencing the ciliate distributions. How can I do that in R, when I have one data frame where the abundance of each species at the 33 sites are listed and one data frame where 12 different environmental parameters of the 33 sites are listed? So e.g. with the following data
#Create random dataframe of abundance data, I am sure this can be done simpler and more elegant than this ;)
species<-c("spec1", "spec2", "spec3", "spec 4", "spec 5", "spec 6", "spec7")
site1<-c(2,4,19,34,3,6,9)
site2<-c(5,8,9,12,0,1,1)
site3<-c(23,56,7,1,1,1,2)
site4<-c(4,6,2,8,5,1,7)
abundance<-data.frame(species,site1,site2,site3,site4)
rownames(abundance)<-abundance$species
abundance<-abundance[,-1]
#Create random dataframe of abundance data
#environmental parameters of the sites
X<-c("site1","site2","site3","site4")
Temp<-c(24,24.5,23.5,25)
Chla<-c(2.2,1.5,2.0,3.4)
Salinity<-c(24,25,26,23)
Depth<-c(200,400,600,200)
environment<-data.frame(X,Temp,Chla,Salinity,Depth)
rownames(environment)<-environment$X
environment<-environment[,-1]
###PCA on abundance data
#hellinger pre-transformation of abundance data
??decostand
library(vegan)
abu.h<-decostand(abundance,"hellinger")
abu.h.pca<-prcomp(abu.h)
biplot(abu.h.pca)
##and now I would need to discard the sites vectors and overlay it with
#the environmental sites factors, due to my prof?
?prcomp
envir.PCA<-prcomp(environment,scale = TRUE)
biplot(envir.PCA)
?biplot