how to add specnames to rankabuncomp?
的后续行动来自用户Jari Oksanen的以下代码帮助在同一平面上逐一绘制曲线。
library(BiodiversityR)
data(dune, dune.env)
## list of models
mods <- with(dune.env, lapply(levels(Management), function(lev)
rankabundance(dune, dune.env, 'Management', lev)))
## level 4 seems to be most extreme: draw it first
rankabunplot(mods[[4]],scale='abundance', addit=FALSE, specnames=c(1,2,3))
## add the rest
## change colour etc to separate the lines if wished
rankabunplot(mods[[3]],scale='abundance', addit=TRUE, specnames=c(1,2,3))
rankabunplot(mods[[2]],scale='abundance', addit=TRUE, specnames=c(1,2,3))
rankabunplot(mods[[1]],scale='abundance', addit=TRUE, specnames=c(1,2,3))
如果我们在一个平面上拟合多条曲线,物种名称彼此重叠,我试图分面,以便每条曲线将驻留在一个区域中(如果多条曲线在一个平面上,则避免重叠物种名称)。
我知道?rankabunplot
和?rankabuncomp
没有facet
参数,所以我无法添加facet_grid()
或facet_wrap
rankabunplot
命令中的任何位置。
然后我将mods矩阵保存为数据帧,然后执行ggplot
。请查看以下步骤是否可以合并到rankabunplot
而不是ggplot
- 以便我不必将mods[[1]]
,mods[[2]]
等保存为单独的与ggplot2
一起使用的数据框。任何帮助表示赞赏。
ggplot(dune.mod, aes(x= rank, y= abundance, label=species))+
geom_line() +
facet_wrap(~mod)+
geom_point()+
geom_text(aes(label=ifelse(rank<4,as.character(species),'')),hjust=0,vjust=0)
我只想要三种最丰富的物种rank<4
。
来自
dune.mod <-
structure(list(species = structure(c(15L, 12L, 14L, 17L, 13L,
19L, 21L, 6L, 9L, 4L, 20L, 3L, 10L, 2L, 1L, 11L, 8L, 18L, 7L,
5L, 16L, 19L, 6L, 2L, 8L, 27L, 21L, 4L, 16L, 26L, 10L, 23L, 22L,
13L, 14L, 24L, 18L, 1L, 5L, 25L, 12L, 28L), .Label = c("Achimill",
"Agrostol", "Alopgeni", "Anthodor", "Bellpere", "Bracruta", "Bromhord",
"Eleopalu", "Elymrepe", "Juncarti", "Juncbufo", "Lolipere", "Planlanc",
"Poaprat", "Poatriv", "Ranuflam", "Rumeacet", "Sagiproc", "Scorautu",
"Trifprat", "Trifrepe", "Airaprae", "Callcusp", "Comapalu", "Empenigr",
"Hyporadi", "Salirepe", "Vicilath"), class = "factor"), rank = c(1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 17L, 18L, 19L, 20L, 21L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L
), abundance = c(24L, 20L, 17L, 16L, 15L, 14L, 14L, 14L, 10L,
9L, 9L, 8L, 8L, 7L, 6L, 6L, 4L, 4L, 4L, 2L, 2L, 19L, 17L, 13L,
13L, 11L, 11L, 8L, 8L, 7L, 7L, 7L, 5L, 5L, 4L, 4L, 3L, 2L, 2L,
2L, 2L, 1L), proportion = c(11.3, 9.4, 8, 7.5, 7, 6.6, 6.6, 6.6,
4.7, 4.2, 4.2, 3.8, 3.8, 3.3, 2.8, 2.8, 1.9, 1.9, 1.9, 0.9, 0.9,
12.6, 11.3, 8.6, 8.6, 7.3, 7.3, 5.3, 5.3, 4.6, 4.6, 4.6, 3.3,
3.3, 2.6, 2.6, 2, 1.3, 1.3, 1.3, 1.3, 0.7), plower = c(8.4, 3.7,
4.9, 1.1, -0.7, 5.2, 3.3, 1.9, -3.6, -0.8, -1.4, -3.1, -2.8,
-2.6, -0.3, -2.5, -3.4, -1.4, -1.4, -1.7, -1.7, 6, 2.6, -1.2,
-1.4, -0.2, -2, -3.8, -1.2, -3.8, -2.7, -2.8, -2.4, -2.6, -2.5,
-1.8, -2.9, -2.4, -2, -1.9, -2, -1), pupper = c(14.1, 15.1, 11.1,
13.9, 14.7, 8, 9.8, 11.2, 13, 9.2, 9.9, 10.6, 10.3, 9.1, 5.9,
8.1, 7.2, 5.2, 5.1, 3.5, 3.6, 19.2, 19.9, 18.4, 18.6, 14.8, 16.6,
14.4, 11.8, 13.1, 12, 12.1, 9, 9.2, 7.8, 7.1, 6.9, 5, 4.7, 4.6,
4.7, 2.3), accumfreq = c(11.3, 20.7, 28.6, 36.2, 43.2, 49.8,
56.3, 62.9, 67.6, 71.8, 76.1, 79.8, 83.6, 86.9, 89.7, 92.5, 94.4,
96.2, 98.1, 99.1, 100, 12.6, 23.8, 32.5, 41.1, 48.3, 55.6, 60.9,
66.2, 70.9, 75.5, 80.1, 83.4, 86.8, 89.4, 92.1, 94, 95.4, 96.7,
98, 99.3, 100), logabun = c(1.4, 1.3, 1.2, 1.2, 1.2, 1.1, 1.1,
1.1, 1, 1, 1, 0.9, 0.9, 0.8, 0.8, 0.8, 0.6, 0.6, 0.6, 0.3, 0.3,
1.3, 1.2, 1.1, 1.1, 1, 1, 0.9, 0.9, 0.8, 0.8, 0.8, 0.7, 0.7,
0.6, 0.6, 0.5, 0.3, 0.3, 0.3, 0.3, 0), rankfreq = c(4.8, 9.5,
14.3, 19, 23.8, 28.6, 33.3, 38.1, 42.9, 47.6, 52.4, 57.1, 61.9,
66.7, 71.4, 76.2, 81, 85.7, 90.5, 95.2, 100, 4.8, 9.5, 14.3,
19, 23.8, 28.6, 33.3, 38.1, 42.9, 47.6, 52.4, 57.1, 61.9, 66.7,
71.4, 76.2, 81, 85.7, 90.5, 95.2, 100), mod = c("m2", "m2", "m2",
"m2", "m2", "m2", "m2", "m2", "m2", "m2", "m2", "m2", "m2", "m2",
"m2", "m2", "m2", "m2", "m2", "m2", "m2", "m3", "m3", "m3", "m3",
"m3", "m3", "m3", "m3", "m3", "m3", "m3", "m3", "m3", "m3", "m3",
"m3", "m3", "m3", "m3", "m3", "m3")), .Names = c("species", "rank",
"abundance", "proportion", "plower", "pupper", "accumfreq", "logabun",
"rankfreq", "mod"), row.names = c(NA, -42L), class = "data.frame")