为什么在 R 中使用 geom_boxplot 会出现一行点而不是箱线图

问题描述 投票:0回答:1

我一直在尝试绘制 4 个不同组中特定门的相对丰度。

我不知道为什么,但是当我用抖动绘制箱线图时,我在中间得到一行点而不是箱线图。

我绘制图像的代码是这样的:

my_plot <- my_data %>%
ggplot(aes(x=group, y=rel_abund, color=group) +
geom_boxplot() +
geom_jitter(size=0.4, alpha=0.9) +
facet_wrap(~taxon, nrow=1, scales = "free_y") +
ylab("Relative Abundance") +
xlab("Group") + 
theme(text=element_text(family="Times"),legend.position = "none")

数据:

structure(list(group = c("1", "1", "1", "1", "1", "1", "1", "1", 
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"), 
    rel_abund = c(0.0224489795918367, 0.0510204081632653, 0.00816326530612245, 
    0.0714285714285714, 0.0489795918367347, 0.036734693877551, 
    0.00204081632653061, 0.0102040816326531, 0.0142857142857143, 
    0.00408163265306122, 0.00816326530612245, 0, 0, 0.00408163265306122, 
    0, 0.00408163265306122, 0.00204081632653061, 0.00204081632653061, 
    0, 0.00204081632653061), level = c("phylum", "phylum", "phylum", 
    "phylum", "phylum", "phylum", "phylum", "phylum", "phylum", 
    "phylum", "phylum", "phylum", "phylum", "phylum", "phylum", 
    "phylum", "phylum", "phylum", "phylum", "phylum"), taxon = c("Firmicutes", 
    "Actinobacteriota", "Firmicutes", "Firmicutes", "Proteobacteria", 
    "Firmicutes", "Proteobacteria", "Actinobacteriota", "Proteobacteria", 
    "Firmicutes", "Proteobacteria", "Firmicutes", "Proteobacteria", 
    "Firmicutes", "Actinobacteriota", "Actinobacteriota", "Firmicutes", 
    "Bacteroidota", "Actinobacteriota", "Firmicutes")), row.names = c(NA, 
-20L), class = c("tbl_df", "tbl", "data.frame"))

非常感谢任何帮助!

r ggplot2 boxplot
1个回答
0
投票

在最后一步中,出现错误“Error in my_data %>% geom_boxplot() : Could not find function "%>%”

© www.soinside.com 2019 - 2024. All rights reserved.