accumulation curve in R
我有几个月内在 4 个地点的物种数据。我已经使用 R 中的
起初我有一个包含所有站点和月份的数据表,但是当我绘制
因此,我将每个站点拆分成一个单独的数据表,然后加载到 R 中。在每个数据表中,第一行是物种名称,下面的每一行是一个月。
例如,我加载了我的网站"FMR"之一的数据。然后我做了以下事情:
1 2 | FMR <-specaccum(FMRJ2F,"random") plot(FMR) |
我对其他网站
你可以在
中使用
1 2 3 4 5 | library(vegan) data(BCI) df <- lapply(c(1,21,41,61,81),function(i)specaccum(BCI[,seq(i,i+19)], method="random")) plot(df[[1]]) for (i in 2:5) plot(df[[i]],add=T, col=i) |
1 2 3 4 5 6 7 8 | library(vegan) data(BCI) sp1 <- specaccum(BCI, 'random') # random modification to BCI data to create data for a second curve BCI2 <- as.matrix(BCI) BCI2[sample(prod(dim(BCI2)), 10000)] <- 0 sp2 <- specaccum(BCI2, 'random') |
绘图
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # Combine the specaccum objects into a list l <- list(sp1, sp2) # Calculate required y-axis limits ylm <- range(sapply(l, '[[', 'richness') + sapply(l, '[[', 'sd') * c(-2, 2)) # Apply a plotting function over the indices of the list sapply(seq_along(l), function(i) { if (i==1) { # If it's the first list element, use plot() with(l[[i]], { plot(sites, richness, type='l', ylim=ylm, xlab='Sites', ylab='random', las=1) segments(seq_len(max(sites)), y0=richness - 2*sd, y1=richness + 2*sd) }) } else { with(l[[i]], { # for subsequent elements, use lines() lines(sites, richness, col=i) segments(seq_len(max(sites)), y0=richness - 2*sd, y1=richness + 2*sd, col=i) }) } }) legend('bottomright', c('Site 1', 'Site 2'), col=1:2, lty=1, bty='n', inset=0.025) |