【发布时间】:2022-08-12 20:57:13
【问题描述】:
我在 R 中有一个 phyloseq 对象,我想生成散点图以显示单个分类群与我的样本数据中的数字变量之间的关联(即我在 x 轴上的变量,在 y 轴上的特定分类群的丰度)。 我想我需要制作某种循环功能,但我有点坚持如何开始使用它!
标签: correlation phyloseq
我在 R 中有一个 phyloseq 对象,我想生成散点图以显示单个分类群与我的样本数据中的数字变量之间的关联(即我在 x 轴上的变量,在 y 轴上的特定分类群的丰度)。 我想我需要制作某种循环功能,但我有点坚持如何开始使用它!
标签: correlation phyloseq
请参阅下面的tidyverse 解决方案。我使用来自phyloseq 的GlobalPatterns 数据创建了一个可重现的示例。我没有足够的声誉来发布图片,但是output should look like this
require("phyloseq")
require("tidyverse")
# Load the data
data(GlobalPatterns)
# Create a continuous x-variable
sample_data(GlobalPatterns)$Variable <- rnorm(nsamples(GlobalPatterns))
# select a single taxon from
set.seed(1)
taxon <- sample(taxa_names(GlobalPatterns), size = 1)
# Function that create a scatterplot between a continuous variable (x)
# and the abundance of a taxon (y)
physeq_scatter_plot <- function(ps, variable, taxon){
# Subset to taxon
ps <- prune_taxa(x = ps, taxa = taxon)
# Convert to long data format
psdf <- psmelt(ps)
# Plot
psdf %>%
ggplot(aes_string(x = variable,
y = "Abundance")) +
geom_point()
}
physeq_scatter_plot(ps = GlobalPatterns, variable = "Variable", taxon = taxon)
#> Warning in prune_taxa(taxa, phy_tree(x)): prune_taxa attempted to reduce tree to 1 or fewer tips.
#> tree replaced with NULL.
由reprex package (v2.0.1) 于 2022 年 8 月 12 日创建
【讨论】: