在 R 中按食物组绘制丰度
Plotting abundance by food group in R
我有一个数据框
1 col = sample ID
2 col = bacteria phyla (out of 7 groups)
3 col = bacteria abundance
4 col = fiber category (out of normal, high, low.)
我想用不同的门群作为填充,纤维类别作为 x 轴(所以 3 条高、低和正常)与 y 轴上的相对丰度进行绘制。
Sample Phyla Abundance FiberCategory
42226 Fusobacteria 0.000007990 Normal
42226 Verrucomicrobia 0.000003990 Normal
42226 Other 0.003485600 Normal
42226 Bacteroidetes 0.403487198 Normal
42226 Firmicutes 0.577910 Normal
42226 Proteobacteria 0.0010 Normal
42226 Actinobacteria 0.0140 Normal
311101 Fusobacteria 0.00 Normal
311101 Verrucomicrobia 0.003 Normal
311101 Other 0.0009 Normal
311101 Proteobacteria 0.000743013 Normal
311101 Bacteroidetes 0.338208944 Normal
311101 Actinobacteria 0.004665200 Normal
311101 Firmicutes 0.654 Normal
4921103 Other 0.000191938 Low
4921103 Fusobacteria 0.000000000 Low
4921103 Actinobacteria 0.000246777 Low
4921103 Proteobacteria 0.007608959 Low
4921103 Verrucomicrobia 0.000004570 Low
4921103 Firmicutes 0.267081313 Low
4921103 Bacteroidetes 0.724866443 Low
我已经试过了ggplot(vg, aes(x = VegetablesCategory, y = Abundance, fill = Phyla))
但是它说剧情损坏了..
有人可以建议如何解决这个问题吗?
在您的代码中,您没有向图中添加任何图层。此外,您可能希望通过 FiberCategory 和 Phyla:
聚合数据
library(ggplot2)
library(dplyr)
vg %>% group_by(FiberCategory, Phyla) %>% summarise(Abundance = sum(Abundance)) %>%
ggplot(aes(x = FiberCategory, y = Abundance, fill = Phyla)) + geom_bar(stat = "identity")
结果:
我有一个数据框
1 col = sample ID
2 col = bacteria phyla (out of 7 groups)
3 col = bacteria abundance
4 col = fiber category (out of normal, high, low.)
我想用不同的门群作为填充,纤维类别作为 x 轴(所以 3 条高、低和正常)与 y 轴上的相对丰度进行绘制。
Sample Phyla Abundance FiberCategory
42226 Fusobacteria 0.000007990 Normal
42226 Verrucomicrobia 0.000003990 Normal
42226 Other 0.003485600 Normal
42226 Bacteroidetes 0.403487198 Normal
42226 Firmicutes 0.577910 Normal
42226 Proteobacteria 0.0010 Normal
42226 Actinobacteria 0.0140 Normal
311101 Fusobacteria 0.00 Normal
311101 Verrucomicrobia 0.003 Normal
311101 Other 0.0009 Normal
311101 Proteobacteria 0.000743013 Normal
311101 Bacteroidetes 0.338208944 Normal
311101 Actinobacteria 0.004665200 Normal
311101 Firmicutes 0.654 Normal
4921103 Other 0.000191938 Low
4921103 Fusobacteria 0.000000000 Low
4921103 Actinobacteria 0.000246777 Low
4921103 Proteobacteria 0.007608959 Low
4921103 Verrucomicrobia 0.000004570 Low
4921103 Firmicutes 0.267081313 Low
4921103 Bacteroidetes 0.724866443 Low
我已经试过了ggplot(vg, aes(x = VegetablesCategory, y = Abundance, fill = Phyla))
但是它说剧情损坏了..
有人可以建议如何解决这个问题吗?
在您的代码中,您没有向图中添加任何图层。此外,您可能希望通过 FiberCategory 和 Phyla:
聚合数据library(ggplot2)
library(dplyr)
vg %>% group_by(FiberCategory, Phyla) %>% summarise(Abundance = sum(Abundance)) %>%
ggplot(aes(x = FiberCategory, y = Abundance, fill = Phyla)) + geom_bar(stat = "identity")
结果: