gpt4 book ai didi

r - 如何在barplot中手动放置错误行?

转载 作者:行者123 更新时间:2023-12-03 08:54:04 24 4
gpt4 key购买 nike

我现在尝试修复手动在错误栏中创建错误栏的问题?有可能吗,如果可以,我该怎么做?此外,是否可能以及如何在绘图之间添加文本以显示显着性水平? (例如Barplot with significant differences and interactions?)

我将不胜感激!

我的代码如下所示:

pdf(file="barplo1.pdf",  title="WHAT TITLE HERE?", pointsize=6, width=4, height=4, paper="special")
par(mfrow = c(3, 2), oma=c(0.5,0.5,0.5,0.5), mar=c(2,5,2,2))
barplot(c(36.5,49.8), names.arg = c("Low", "High"), beside = TRUE, ylab = "", main="Power", col = c("grey", "gray50"), ylim = c(0,100), cex.lab=1.7, cex.axis = 1.4, cex.names = 1.4, cex.main = 1.8, lwd = 0.5, border = NA)
text(0.71,39.5, "36,5 pct.***", pos=3, cex= 1.4)
text(1.9,52.8, "49,8 pct.***", pos=3, cex= 1.4)
barplot(c(39.5,50.6), names.arg = c("Low", "High"), beside = TRUE, main="", col = c("grey", "gray50"), ylim = c(0,100), cex.axis = 1.4, cex.names = 1.4, cex.main = 1.8, lwd = 0.5, border = NA)
text(0.71,42.5, "39,5 pct.***", pos=3, cex= 1.4)
text(1.9,53.6, "50,6 pct.***", pos=3, cex= 1.4)
barplot(c(33.5,50.1), names.arg = c("Low", "High"), beside = TRUE, ylab = "", col = c("grey", "gray50"), ylim = c(0,100), cex.lab=1.7, cex.axis = 1.4, cex.names = 1.4, lwd = 0.5, border = NA)
text(0.71,36.5, "33,5 pct.***", pos=3, cex= 1.4)
text(1.9,53.1, "50,1 pct.***", pos=3, cex= 1.4)
barplot(c(49.5,61.5), names.arg = c("Low", "High"), beside = TRUE, col = c("grey", "gray50"), ylim = c(0,100), cex.axis = 1.4, cex.names = 1.4, lwd = 0.5, border = NA)
text(0.71,52.5, "49,5 pct.***", pos=3, cex= 1.4)
text(1.9,64.5, "61,5 pct.***", pos=3, cex= 1.4)
barplot(c(40.0,48.5), names.arg = c("Low", "High"), beside = TRUE, col = c("grey", "gray50"), ylim = c(0,100), ylab = "", cex.lab=1.7, cex.axis = 1.4, cex.names = 1.4, lwd = 0.5, border = NA)
text(0.71,43.0, "40,0 pct.***", pos=3, cex= 1.4)
text(1.9,51.5, "48,5 pct.***", pos=3, cex= 1.4)
barplot(c(45.5,70.2), names.arg = c("Low", "High"), beside = TRUE, col = c("grey", "gray50"), ylim = c(0,100), cex.axis = 1.4, cex.names = 1.4, lwd = 0.5, border = NA)
text(0.71,48.5, "45,5 pct.***", pos=3, cex= 1.4)
text(1.9,73.2, "70,2 pct.***", pos=3, cex= 1.4)
dev.off()

最佳答案

为此,您需要将每次对barplot()的调用运行两次,一次以获取要绘制的每个条形图的中点带有x坐标的 vector ,然后再次进行绘制。然后,绘制完图后,您可以使用segments()在每个条形的中间添加一条表示CI的线。这是一个简单的例子:

x <- c(4, 3, 7)
z <- barplot(x, plot=FALSE) # This returns a vector with the x-axis midpoints of the bars it would have drawn; they are *not* integers, which is why this is tricky
png("barplot.with.cis.png", width=5, height=5, unit="in", res=150)
par(mai=c(0.5,0.5,0.1,0.1))
barplot(x)
segments(x0=z, x1=z, y0=x-1, y1=x+1)
dev.off()

产生这个情节:

enter image description here

在您的情况下,您希望在调用 segments()时插入CI的上下边界作为y0和y1 vector 。您还可以将该 z vector 用作文本注释的x坐标;相应的值将是您的y坐标。

最后,请注意,您需要在对 ylim的调用中设置 barplot(x),以留出留给CI的空间。您还可以使用 ylim=c(0, ceiling(max([vector of CI upper bounds])))之类的东西来限制CI的上限。

关于r - 如何在barplot中手动放置错误行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31994742/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com