我正在努力使用ggplot2制作特定的barplot。 对于感兴趣的基因,我想显示两个样本中的基因计数。 X轴应该有样本,Y轴应该是计数的平均值,它应该有误差线并显示独立的t检验的结果,以测试两个样本之间的显着差异。
这是显示平均值计数和误差线的条形图:
genecounts <- data.frame(
sample = c("control", "control", "condition", "condition"),
counts = c(7.9, 4.2, 5.2, 7.7)
)
genecounts2 <- genecounts %>%
group_by(sample) %>%
summarise(mean = mean(counts), sd = sd(counts))
barplot <- ggplot(genecounts2) +
geom_bar(
aes(x = sample, y = mean),
stat = "identity"
) +
geom_errorbar(
aes(x = sample, ymax = mean + sd, ymin = mean - sd),
width = 0.25
) +
labs(y = "mean normalized counts", x = "gene name")
如何添加重要性标签? 我尝试使用ggpubr或ggsignif。到目前为止,我发现的所有解决方案都将数据表用作基础,您可以在其中找到所有样品的计数。但是我想在仅显示所有样本计数均值的条形图上进行此操作。想法受到高度赞赏!
我的想法:
library("ggpubr")
paircomparison <- list(c("control", "condition"))
barplot + stat_compare_means(comparisons = paircomparison)
# OR
barplot + stat_compare_means(data = genecounts, aes(x = sample, y = counts), comparisons = paircomparison)
Error in f(...) :
Can only handle data with groups that are plotted on the x-axis
它看起来可能与此类似: