I'm plotting PCA results from R Vegan using the ggord graphics package.
I want to plot the PCA graph without adding environmental variables. In R Vegan, the PCA can be plotted with no problem, but in ggord, the same graph will not work. The example given by the ggord documentation includes code for an environmental data set that draws vectors over the PCA graph. I would like to graph the same results in ggord that I can create in vegan, without the environmental vectors.
The code in Vegan, using a sample data set, which produces the sort of graph I want:
ord<-rda(varespec, scale = TRUE)
ord
plot(ord, scaling=3)
The ggord documentation uses the same data set to create the same graph, except that it includes an environmental data set:
data(varespec)
data(varechem)
ord <- rda(varespec, varechem)
ggord(ord)
However, when I attempt to recreate this graph without the environmental (varechem) data, R gives me an error:
ord <- rda(varespec)
ggord(ord)
Error in names(obs)[1:2] <- axes :
'names' attribute [2] must be the same length as the vector [
I also tried including a dummy variable, which failed and gave me a different error.
dummy<-rep(0, 24)
dummy<-as.data.frame(dummy)
ord<-rda(varespec, dummy)
ord
ggord(ord)
Error in ord_in$CCA$wa[, axes] : no 'dimnames' attribute for array
Is it possible to create this graph without environmental data in ggord, as in Vegan? If so, how do I do so?
Don't forget typing ?ggord
is a great way to find out the options available in a function.
Try this:
library(vegan)
library(ggord)
data(varespec)
data(varechem)
names(varechem)<-NULL
ord <- rda(varespec, varechem,scale=TRUE)
ggo<-ggord(ord,arrow=NULL,ptslab=TRUE,obslab=TRUE)
ggo
Gives: