这篇文章之前已经提出过这样的问题:用条形图表示使用R的统计学差异.但是,他们想知道如何使用ggplot2来做到这一点.我想知道你是如何使用基本包或函数barplot()来做到这一点的.我想要一些如下图所示的内容:
http://i.stack.imgur.com/3I6El.jpg
我目前的代码:
barcenter3<- barplot(newMEANs3$Percent_Viability, names.arg=c("Control", "Cyp28d1", "A3", "A4"), ylab = "Average Emergent", ylim=c(0, 1.1), xlab= "RNAi Line", main = "Trip Nicotine UAS-RNAi Emergents")
segments(barcenter3, newMEANs3$Percent_Viability-newSDs3$Percent_Viability, barcenter3, newMEANs3$Percent_Viability+newSDs3$Percent_Viability, lwd=1);
segments(barcenter3 - 0.1, newMEANs3$Percent_Viability-newSDs3$Percent_Viability, barcenter3 + 0.1, newMEANs3$Percent_Viability-newSDs3$Percent_Viability, lwd=1);
segments(barcenter3 - 0.1, newMEANs3$Percent_Viability+newSDs3$Percent_Viability, barcenter3 + 0.1, newMEANs3$Percent_Viability+newSDs3$Percent_Viability, lwd=1);
dev.off();
Run Code Online (Sandbox Code Playgroud)
我想添加p值比较对比度.
这是一个简单的功能.
## Sample Data
means <- seq(10,40,10)
pvals <- seq(0.01, 0.05, 0.02)
barPs <- function(means, pvals, offset=1, ...) {
breaks <- barplot(means, ylim=c(0, max(means)+3*offset), ...)
ylims <- diff(means) + means[-length(means)] + offset
segments(x0=breaks[-length(breaks)], y0=ylims, x1=breaks[-1], y1=ylims)
segments(x0=c(breaks[-length(breaks)], breaks[-1]),
y0=rep(ylims, each=2), y1=rep(ylims-offset/2, each=2))
text(breaks[-length(breaks)]+diff(breaks[1:2])/2, ylims+offset,
labels=paste("p=", pvals))
}
barPs(means, pvals, offset=1, main="Bar w/ P-value",
names.arg=toupper(letters[1:4]))
Run Code Online (Sandbox Code Playgroud)
