我的问题比这个问题要复杂一些。
我想为每个 Rot.Herb 堆放 10 个最丰富的物种(总共 18 个),并将其他物种分为两大类,即其他单子叶植物和其他双子叶植物。我想我需要手动分配哪个是单子叶植物哪个是双子叶植物。棘手的部分是 10 个最丰富的物种群对于每个 Rot 都是独一无二的。草本植物。
这是所有堆叠的图表:
这是代码:
weedweights<-weeds%>%
select(-ends_with("No"))%>%
gather(key=species, value=speciesmass, DIGSAWt:POLLAWt)%>%
mutate(realmass=speciesmass * samplearea.m.2.)%>%
group_by(Rot.Herb, species)%>%
summarize(avgrealmass=mean(realmass, na.rm=TRUE))%>%
filter(avgrealmass != "NaN")%>%
ungroup()
ggplot(weedweights, aes(x=Rot.Herb, y=avgrealmass, fill=species))+
geom_bar(stat="identity")
你可以在这里看到数据
structure(list(Rot.Herb = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
18L, 18L, 18L, 18L, 18L), .Label = c("A4conv", "A4low", "C2conv",
"C2low", "C3conv", "C3low", "C4conv", "C4low", "O3conv", "O3low",
"O4conv", "O4low", "S2conv", "S2low", "S3conv", "S3low", "S4conv",
"S4low"), class = "factor"), species = c("DIGSA", "SETFA", "SETLU",
"AMATA", "CHEAL", "PHYSU", "TAROF", "EPHHT", "SONAR", "MORAL",
"OXAST", "Unknownmonocot", "DIGSA", "SETFA", "SETLU", "AMATA",
"CHEAL", "SOLPT", "TAROF", "EPHHT", "SONAR", "Unknowndicot",
"Unknownmonocot", "SETFA", "AMATA", "SOLPT", "PHYSU", "TAROF",
"EPHHT", "MORAL", "SETFA", "AMATA", "CHEAL", "SOLPT", "PHYSU",
"POLPY", "ABUTH", "TAROF", "EPHHT", "SONAR", "ASCSY", "SETFA",
"SETLU", "AMATA", "CHEAL", "SOLPT", "PHYSU", "ABUTH", "TAROF",
"MORAL", "DIGSA", "SETFA", "SETLU", "ERBVI", "AMATA", "CHEAL",
"SOLPT", "PHYSU", "ABUTH", "TAROF", "MORAL", "Unknowndicot",
"Unknownmonocot", "DIGSA", "SETFA", "SETLU", "AMATA", "SOLPT",
"PHYSU", "ABUTH", "TAROF", "EPHHT", "SONAR", "MORAL", "OXAST",
"DIGSA", "SETFA", "SETLU", "ECHCG", "AMATA", "CHEAL", "SOLPT",
"PHYSU", "POLPY", "ABUTH", "TAROF", "EPHHT", "OXAST", "POLLA",
"SETFA", "SETLU", "AMATA", "CHEAL", "SOLPT", "POLPY", "TAROF",
"POLAV", "PLAMA", "Unknownmonocot", "SETFA", "SETLU", "AMATA",
"CHEAL", "SOLPT", "PHYSU", "TAROF", "Unknownmonocot", "DIGSA",
"SETFA", "SETLU", "PANCA", "CYPES", "AMATA", "CHEAL", "SOLPT",
"PHYSU", "TAROF", "EPHHT", "CIRAR", "OXAST", "DIGSA", "SETFA",
"SETLU", "PANCA", "CYPES", "AMATA", "CHEAL", "SOLPT", "PHYSU",
"TAROF", "EPHHT", "SONAR", "MORAL", "Unknownmonocot", "AMATA",
"CHEAL", "SOLPT", "PHYSU", "POLPY", "TAROF", "MORAL", "DIGSA",
"SETFA", "PANCA", "ECHCG", "ERBVI", "AMATA", "CHEAL", "SOLPT",
"PHYSU", "ABUTH", "TAROF", "MORAL", "AMATA", "CHEAL", "SOLPT",
"PHYSU", "ABUTH", "TAROF", "MORAL", "Unknowndicot", "SETFA",
"AMATA", "CHEAL", "SOLPT", "ABUTH", "TAROF", "EPHHT", "SETLU",
"ECHCG", "AMATA", "CHEAL", "SOLPT", "PHYSU", "ABUTH", "TAROF",
"EPHHT", "MORAL", "Unknowndicot", "DIGSA", "SETFA", "AMATA",
"CHEAL", "TAROF"), avgrealmass = c(6.25, 26.35, 58.35, 13.4666666666667,
17.1, 1.15, 28.75, 0.45, 0, 0.2, 1.2, 0, 6.425, 18.65, 6.63333333333333,
3.475, 6.11666666666667, 16.1, 41.9625, 0.9, 0, 0, 0, 0.0809410748974746,
0.237427153032592, 0.0917332182171379, 0.0647528599179797, 0.105223397366717,
0, 0.0539607165983164, 0.795920569825167, 5.7818907835096, 13.3822577163825,
1.62151953377941, 3.1099359666163, 0.388517159507878, 0.0539607165983164,
0.0845384560040291, 0.0701489315778114, 0.0539607165983164, 0.0215842866393266,
0.0539607165983164, 54.8240880638895, 0, 0.0269803582991582,
0.102525361536801, 0.0215842866393266, 0.0647528599179797, 0.0404705374487373,
0.0161882149794949, 0.485646449384848, 11.2103388733002, 86.4990287071012,
22.9333045542845, 13.9218648823656, 49.6798330815167, 0.0944312540470537,
0.661018778329376, 0.410101446147205, 0.399309302827542, 0, 1.18173969350313,
0.0161882149794949, 0.134901791495791, 1.24649255342111, 1.95877401251889,
0.00269803582991582, 0.364234837038636, 0.555795380962659, 0.356140729548888,
0.0350744657889057, 0.0944312540470537, 0.00809410748974746,
0.00539607165983164, 0, 1.42186488236564, 15.7794625512627, 0.584574429815095,
11.7094755018347, 1.75372328944528, 2.4552126052234, 0.50992877185409,
0.0863371465573063, 0.221238938053097, 9.53305993236924, 0.106572415281675,
0.117364558601338, 0.075545003237643, 1.40297863155623, 31.45,
14.0666666666667, 18.7375, 15.225, 22.3166666666667, 24.05, 8.775,
1.05, 0.4, 0, 8.55, 35.475, 31.4375, 35.4375, 15.4, 16.55, 7.15,
0, 105.05, 5.775, 0.8, 0.1, 37.85, 23.3375, 6.35, 97.4, 22.925,
138.2875, 8.26666666666667, 0.2, 16.25, 8.075, 28.9, 10.1, 1.05,
8.85, 34.6375, 59.425, 87.7, 4.45, 179.9875, 1.8, 34.45, 0, 0,
0.585473775091733, 0.0161882149794949, 0, 0, 0.113317504856464,
0.305777394057126, 0, 1.61342542628966, 1.62961364126916, 2.36887545866609,
7.94301748327218, 17.4832721778545, 30.8034750701489, 3.40761925318368,
0.627743003093748, 0.582775739261817, 1.46773149147421, 0.0575580977048708,
0.00899345276638607, 0.539607165983164, 0.364234837038636, 0.0431685732786531,
0, 0.407403410317289, 0.0229333045542845, 0, 0, 21.8540902223182,
43.1591301532484, 57.2172458450248, 0.793222533995251, 1.14396719188431,
0.215842866393266, 0.113317504856464, 0.0647528599179797, 0.0917332182171379,
0.453270019425858, 0.0431685732786531, 0.0485646449384848, 0.0161882149794949,
0.879559680552558, 0.00269803582991582, 0.0161882149794949, 0.0143895244262177,
0.0215842866393266, 0.075545003237643, 5.71983595942154, 34.9719404273689,
4.31685732786531, 0)), .Names = c("Rot.Herb", "species", "avgrealmass"
), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-184L))