R 如何创建具有不同物种组的排序图

R 如何创建具有不同物种组的排序图,r,R,我非常感谢你的帮助,因为我是一个彻头彻尾的傻瓜 我在R中创建了一个带有物种列表和环境变量的cca排序图。现在的问题是这些物种属于不同的类群(苔藓、地衣或草本)。我希望地块中的物种点对于每个群体都有不同的颜色!我有一个非常大的物种列表,有很多列,所以我不能单独参考每一列 列名如下所示: herb2 herb2 herb2 herb2 herb2 herb2 herb2 herb2 moss1 moss2地衣 到目前为止,我只有以下代码: env.allspecies.cca<- vegan:

我非常感谢你的帮助,因为我是一个彻头彻尾的傻瓜

我在R中创建了一个带有物种列表和环境变量的cca排序图。现在的问题是这些物种属于不同的类群(苔藓、地衣或草本)。我希望地块中的物种点对于每个群体都有不同的颜色!我有一个非常大的物种列表,有很多列,所以我不能单独参考每一列

列名如下所示:

herb2 herb2 herb2 herb2 herb2 herb2 herb2 herb2 moss1 moss2地衣 到目前为止,我只有以下代码:

env.allspecies.cca<- vegan::cca(alpin.spec, alpin.env)

autoplot(env.allspecies.cca, title = c("CCA"))


env.allspecies.cca类似的东西?[1] :

library(素食主义者)
#使用包含10个物种的一些随机物种数据生成数据框
设定种子(123)#使其可复制

random.spec欢迎来到StackOverflow!看看你的数据样本,考虑使用<代码> DPUTE()/代码>来分享你已经尝试过的数据和代码的样本,这样我们可以帮助你!对这正是我想做的!非常感谢你!
library(vegan)

#Generate a data frame with some random species data containing 10 species
set.seed(123)#make it reproducible
random.spec            <- as.data.frame(matrix(rbinom(100, 10, 0.5), ncol = 10))
colnames(random.spec)  <- paste0('spec', rep(1:10))

#looking at the random.spec data
head(random.spec)

  spec1 spec2 spec3 spec4 spec5 spec6 spec7 spec8 spec9 spec10
1     4     8     7     8     3     2     6     6     4      3
2     6     5     6     7     5     5     3     6     6      6
3     5     6     6     6     5     6     5     6     5      4
4     7     5     9     6     4     3     4     0     6      6
5     7     3     6     2     3     5     6     5     3      4
6     2     7     6     5     3     4     5     4     5      4

#Generate a data frame with some random environmental variables.
set.seed(123)#make it reproducible
random.env             <- as.data.frame(matrix(rnorm(100, 10, 2), ncol = 10))
colnames(random.env)   <- paste0('variable', rep(1:10))

#looking at the random.env data
head(random.env)

  variable1 variable2 variable3 variable4 variable5 variable6 variable7 variable8 variable9
1  8.879049 12.448164  7.864353 10.852928  8.610586 10.506637 10.759279  9.017938 10.011528
2  9.539645 10.719628  9.564050  9.409857  9.584165  9.942906  8.995353  5.381662 10.770561
3 13.117417 10.801543  7.947991 11.790251  7.469207  9.914259  9.333585 12.011477  9.258680
4 10.141017 10.221365  8.542218 11.756267 14.337912 12.737205  7.962849  8.581598 11.288753
5 10.258575  8.888318  8.749921 11.643162 12.415924  9.548458  7.856418  8.623983  9.559027
6 13.430130 13.573826  6.626613 11.377281  7.753783 13.032941 10.607057 12.051143 10.663564
  variable10
1  11.987008
2  11.096794
3  10.477463
4   8.744188
5  12.721305
6   8.799481

#Apply the CCA
results                <- cca(random.spec~., random.env)

#We have 10 species and the first 5 (spec1-spec5) in the data frame belonged to one 
#group and the other 5 (spec6-spec10) to another group. We give the first 5 species 
#in the data frame a red colour and the other 5 a blue colour.
pointcolour            <- c(rep("red", 5), rep("blue", 5))

#We first create an empty plot (type = "n").
plot(results, scaling = 3, display = "species", type = "n",)

#Now we plot the species in the plot with the colours (col = pointcolour).
text(results, display = "species", cex = 1.5, col = pointcolour, scaling = 3)

#As last we plot the environmental variables.
text(results, display = "bp", add = TRUE, col = "grey40", scaling = 3)