【问题标题】:Plotting abundance by food group in R在R中按食物组绘制丰度
【发布时间】:2016-07-21 08:16:19
【问题描述】:

我有一个数据框

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)),但它说情节已损坏..

有人可以建议如何解决这个问题吗?

【问题讨论】:

    标签: r dataframe plot reshape


    【解决方案1】:

    在您的代码中,您没有在绘图中添加任何图层。此外,您可能希望按 FiberCategoryPhyla 聚合您的数据:

    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")
    

    结果:

    【讨论】:

    • 此图出现在 x 上的细菌门和纤维类别作为填充。我想要门作为填充物。此外,门结果没有排序。所以条形图(绿色,蓝色,橙色,再次绿色,紫色等)。有没有办法将总丰度颜色组放在一起?谢谢!
    • 我不确定我们是否得到相同的情节...我编辑添加了图片。你也一样吗?有些门根本没有出现,因为与拟杆菌门和厚壁菌门相比,它们的数量太少而无法看到。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-25
    • 2021-12-19
    • 1970-01-01
    • 1970-01-01
    • 2015-05-04
    相关资源
    最近更新 更多