Как создать ординационные сюжеты с различными группами видов - PullRequest
0 голосов
/ 21 апреля 2020

Я благодарен за любую помощь, так как я полный R noob.

Я создал ординационный участок cca в R со списком видов и переменными среды. Теперь проблема в том, что виды принадлежат к разным группам (мхи, лишайники или травы). Я хочу, чтобы видовые точки на участках имели разные цвета для каждой группы! У меня очень большой список видов со многими столбцами, поэтому я не могу ссылаться на каждый столбец отдельно.

Названия столбцов выглядят следующим образом:

herb1 herb2 herb3 herb3 мосс1 мох2 лишайник1 единственный код, который у меня есть до сих пор это:

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

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

Я пытался разделить набор данных видов на alpin.spe c .herb, alpin.spe c .moss, alpin.spe c .lichen

но я не смог прийти к выводу.

Как я могу построить так, чтобы все точки травяного вида имели одинаковый цвет?

Или, может быть, я могу поместить столбцы в группы и построить эти группы?

1 Ответ

1 голос
/ 24 апреля 2020

Как то так? [1]: https://i.stack.imgur.com/tNz2X.jpg

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)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...