R 创建具有平均丰度的堆叠条形图
我试图创建一个堆积条形图,y轴上有平均丰度,x轴上有主要营养组,每个条形图将由特定营养组填充(主要营养组进一步细分) 我已经创建了一个我的数据示例,您应该能够直接将其放入R中:R 创建具有平均丰度的堆叠条形图,r,ggplot2,bar-chart,mean,data-manipulation,R,Ggplot2,Bar Chart,Mean,Data Manipulation,我试图创建一个堆积条形图,y轴上有平均丰度,x轴上有主要营养组,每个条形图将由特定营养组填充(主要营养组进一步细分) 我已经创建了一个我的数据示例,您应该能够直接将其放入R中: Example<-structure(list(Species = c("Fish1", "Fish2", "Fish3", "Fish4", "Fish5", "Fish6", "Fish7", "Fish1", "Fish2", "Fish3", "Fish4", "Fish5", "Fish6", "Fi
Example<-structure(list(Species = c("Fish1", "Fish2", "Fish3", "Fish4",
"Fish5", "Fish6", "Fish7", "Fish1", "Fish2", "Fish3", "Fish4",
"Fish5", "Fish6", "Fish7", "Fish1", "Fish2", "Fish3", "Fish4",
"Fish5", "Fish6", "Fish7"), Trophic = c("Herbivore", "Omnivore",
"Herbivore", "Predator", "Predator", "Omnivore", "Omnivore",
"Herbivore", "Omnivore", "Herbivore", "Predator", "Predator",
"Omnivore", "Omnivore", "Herbivore", "Omnivore", "Herbivore",
"Predator", "Predator", "Omnivore", "Omnivore"), Trophic_Specific = c("Grazer",
"Generalist_Omnivore", "Browser", "Micro-invertebrate_Predator",
"Micro-invertebrate_Predator", "Generalist_Omnivore", "Benthic_Omnivore",
"Grazer", "Generalist_Omnivore", "Browser", "Micro-invertebrate_Predator",
"Micro-invertebrate_Predator", "Generalist_Omnivore", "Benthic_Omnivore",
"Grazer", "Generalist_Omnivore", "Browser", "Micro-invertebrate_Predator",
"Micro-invertebrate_Predator", "Generalist_Omnivore", "Benthic_Omnivore"
), Transect = c(1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3,
3, 3, 3, 3, 3, 3), Count = c(1, 2, 34, 0, 4, 2, 1, 0, 2, 25,
1, 4, 2, 1, 1, 4, 50, 3, 6, 7, 3)), class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -21L), spec = structure(list(
cols = list(Species = structure(list(), class = c("collector_character",
"collector")), Trophic = structure(list(), class = c("collector_character",
"collector")), Trophic_Specific = structure(list(), class = c("collector_character",
"collector")), Transect = structure(list(), class = c("collector_double",
"collector")), Count = structure(list(), class = c("collector_double",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), skip = 1), class = "col_spec"))
Example我不是100%相信这就是你要找的,但我想我会试一试
library(tidyverse)
Example %>%
group_by(Trophic, Trophic_Specific) %>%
summarise(Mean = mean(Count),
SD = sd(Count),
n = n(),
SE = SD/n)
# A tibble: 5 x 6
# Groups: Trophic [3]
Trophic Trophic_Specific Mean SD n SE
<chr> <chr> <dbl> <dbl> <int> <dbl>
1 Herbivore Browser 36.3 12.7 3 4.22
2 Herbivore Grazer 0.667 0.577 3 0.192
3 Omnivore Benthic_Omnivore 1.67 1.15 3 0.385
4 Omnivore Generalist_Omnivore 3.17 2.04 6 0.340
5 Predator Micro-invertebrate_Predator 3 2.19 6 0.365
库(tidyverse)
示例%>%
组别(营养性,营养性)%>%
总结(平均值=平均值(计数),
SD=SD(计数),
n=n(),
SE=SD/n)
#一个tibble:5x6
#组别:营养型[3]
营养性营养素比平均值SD n SE
1草食动物浏览器36.3 12.7 3 4.22
2食草动物食草动物0.667 0.577 3 0.192
3杂食性底栖动物_杂食性1.67 1.15 3 0.385
4杂食多面手_杂食3.17 2.04 6 0.340
5捕食者微型无脊椎动物3 2.19 6 0.365
这正是我想要的!非常感谢!