无法在 R 包 Divnet 生成的 phyloseq 对象上按组绘图

发布于 2025-01-14 06:54:54 字数 572 浏览 3 评论 0原文

我打算绘制我的样本的 alpha 多样性图,该图由三组组成。 Alpha多样性是通过R包Divnet计算的。它涉及使用 phyloseq 作为依赖项。

每个样本的组在 phyloseq 对象“df_family”中的 sam_data、列“type”中指定 “dv”是由多样性估计和标准误差组成的列表。

这是我使用的代码:

dv$shannon %>% plot(df_family, color = "type", group = df_family@sam_data$type) +
 xlab("sample type") +
 ylab("Shannon diversity estimate (family level)") +
 coord_cartesian(ylim = c(0,5))`

这是我得到的:

样本是独立显示的,而不是聚集为一组 myplot1

这是我想要得到的: 预期情节2

I intend to plot an alpha diversity plot of my samples, which consist of three groups.
Alpha diversity is calculated by R package Divnet. It involve using phyloseq as a dependency.

The group of each sample is specified in a sam_data, column "type" in phyloseq object "df_family"
"dv" is list composed of diversity estimates and standard errors.

Here is the code I used:

dv$shannon %>% plot(df_family, color = "type", group = df_family@sam_data$type) +
 xlab("sample type") +
 ylab("Shannon diversity estimate (family level)") +
 coord_cartesian(ylim = c(0,5))`

Here is what I get:

The samples were shown independently, instead of clustered as a group
my plot1

Here is what I intend to get:
intended plot2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只是我以为 2025-01-21 06:54:54

一旦您有了 phyloseq 对象 df_family,您就可以使用 phyloseq 中的函数 estimate_richness
然后,您可以将示例元数据连接到该 alpha 多样性数据框。
最后,您可以直接使用 ggplot2 来相应地自定义绘图,例如在 x 轴上放置不同的样本组(此处为 SampleType):

library(tidyverse)
library(phyloseq)

# get example phy object
otufile <- system.file("extdata", "GP_otu_table_rand_short.txt.gz", package = "phyloseq")
mapfile <- system.file("extdata", "master_map.txt", package = "phyloseq")
df_family <- import_qiime(otufile, mapfile, trefile, showProgress = FALSE)

alphadiv <-
  df_family %>%
  estimate_richness() %>%
  as_tibble(rownames = "sample_id") %>%
  left_join(df_family@sam_data %>% as_tibble(rownames = "sample_id"))
alphadiv

alphadiv %>%
  ggplot(aes(x = SampleType, y = Shannon)) +
  geom_boxplot()

在此处输入图像描述

您还可以添加额外的aes 中的示例属性,例如 aes(x = SampleType, y = Shannon, color = my_group) 如果 my_group 是单元格包含 f、li 或 si 的示例属性列。

Once you already have your phyloseq object df_family, you can use the function estimate_richness from phyloseq.
You can then join the sample meta data to this data frame of alpha diversities.
Finally, you can use ggplot2 directly to customize your plot accordingly, e.g. to put different sample groups (here SampleType) at your x axis:

library(tidyverse)
library(phyloseq)

# get example phy object
otufile <- system.file("extdata", "GP_otu_table_rand_short.txt.gz", package = "phyloseq")
mapfile <- system.file("extdata", "master_map.txt", package = "phyloseq")
df_family <- import_qiime(otufile, mapfile, trefile, showProgress = FALSE)

alphadiv <-
  df_family %>%
  estimate_richness() %>%
  as_tibble(rownames = "sample_id") %>%
  left_join(df_family@sam_data %>% as_tibble(rownames = "sample_id"))
alphadiv

alphadiv %>%
  ggplot(aes(x = SampleType, y = Shannon)) +
  geom_boxplot()

enter image description here

You can also add additional sample properties in aes e.g. aes(x = SampleType, y = Shannon, color = my_group) if my_group is a sample property column with cells containing f, li, or si.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文