我正在R中绘制一系列RDA,每个RDA都有10多个环境向量。每个环境变量都属于5个类别之一。我希望矢量颜色能够反射(reflect)这些类别。我通过制作原始的黑白情节,然后在Powerpoint中进行跟踪(非常耗时)来以某种贫民窟的方式来做,但是这样做有很多固有的问题,但至少看起来不错。
这是情节,请注意矢量颜色。
我想让我的输出是R native 绘图。我现在用来制作基本图的图是:
#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)
我假设答案就在这点上-> col =“...”命令,但是我不确定如何按组将其告诉子集。任何和所有帮助将不胜感激。
最佳答案
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)
关于r - 按R中的组对RDA向量进行着色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47658880/