RDA color vectors by groups in R

I draw a series of RDA in R, each of which has 10+ environmental vectors. Each of the environmental variables belongs to one of five categories. I would like vector colors to reflect these categories. I did it in several ghettos, creating an unprocessed black and white plot, and then tracing it to Powerpoint (time spent on a lot of time), but there are many reasons for this, but at least it looks good. Here is this plot, pay attention to vector colors. enter image description here

I want my result to be an R-native plot. The plot that I use to create the base chart is currently:

#download the data# env<- read.csv("environmenta data.csv") bio<- read.csv("bio data.csv") #break out the groups of environmental vectors# #these are purley for example# group1<-as.matrix(subset(env,select=c(a,b,c)) group2<-as.matrix(subset(env,select=c(d,e,f,h)) group3<-as.matrix(subset(env,select=c(g)) group4<-as.matrix(subset(env,select=c(j,k,l,o)) group5<-as.matrix(subset(env,select=c(m,n,)) #run the RDA# rda1<-rda(bio,env) #Plot it# plot(rda1,type="n",bty="n",main="", xlab="XX% variance explained", ylab="XX% variance explained", col.main="black",col.lab="black", col.axis="white", xaxt="n",yaxt="n") #points(rda1,display="species",col="gray",pch=20) #option to display species points #text(rda2,display="species",col="gray") #option for species labels points(rda1,display="cn",col="black",lwd=2)#<<< guessing this is the key statement for my issue, but not sure text(rda1,display="cn",col="black",cex=0.5) 

I assume that the answer gets to this point → col = "...", but I'm not sure how to talk about this subset in groups. Any help would be greatly appreciated.

+7
r vegan
source share
2 answers
 library(vegan) #DATA data(varespec) data(varechem) env = varechem bio = varespec rm(list = c("varechem", "varespec")) #Assign colors based on groups for the columns of env groups = rep(c("red", "blue"), length.out = NCOL(env)) rda1 = rda(X = bio, Y = env) plot(rda1, type = "n") points(rda1) text(rda1, display = "bp", col = groups) 
+1
source share

There are several issues here:

  • capitalization and
  • scaling biplot scores according to plot.cca

The latter does not really matter if you only plot points, but a general solution to this type of conspiracy requires us to take into account that other ratings may also be required for drawing.

Here's a reproducible example using data embedded in

 library('vegan') data(varespec, varechem) 

Now we are approaching a foolish ordination (do not do this at home)

 ord <- rda(varespec ~ ., data = varechem) 

Then get points

 bp <- scores(ord, display = 'bp') 

and suppose we have a variable containing the groups that we want to assign to each bipole value

 f <- factor(sample(1:5, nrow(bp), replace = TRUE)) 

and the related color vector we want to use

 cols <- c('red','black','green','navy','purple') 

and expand this color vector into one of the long nrow(bp) , i.e. one color for one point / variable

 cols <- cols[f] 

Then start drawing by preparing an empty plot area in which we can add arrows

 plot(ord, type = 'n') 

In the above example, we leave the given plot area in such a way that takes into account the types and evaluation of the site / selection.

Now we calculate the factor that allows the ballogs to occupy the specified proportion ( fill = 0.75 ) of the chart area

 mul <- ordiArrowMul(bp, fill = 0.75) 

Finally, add biplot arrows colored according to their group

 arrows(0, 0, mul * bp[,1], mul * bp[,2], length = 0.05, col = cols) 

and add tags to biplot arrows

 labs <- rownames(bp) text(ordiArrowTextXY(mul * bp, labs), labs, col = cols) 

It creates

enter image description here

+2
source share

All Articles