我使用以下代码创建了一个条形图:
#create function for plotting error bars
errb <- function (x, y, ebl, ebu = ebl, length = 0.08, ...){
arrows(x, y + ebu, x, y - ebl, angle = 90, code = 3,
length = length, ...)
}
#generate plot data
means <- c(0.976,0.664, 1.12, 1.22)
errs <- c(0.16, 0.17, 0.16, 0.16)
#plot labels
names <- c('+NaCl', '+NaCl',expression(paste('+NaNO'[3])),expression(paste('+H'[2]*'O')))
#plot
plot1<-barplot(means, beside=T,border=NA,
ylim=c(0,1.6),
names.arg=names)
errb(plot1,means,ebl=errs,ebu=errs)
box(bty="L")它看起来是这样的:

我想在图的顶部空白处添加一些标签,以指示是否存在处理E。第一个条是(-E),第2-4条是(+E)。我希望结果看起来像这样:

我该如何在base R中做这件事?
发布于 2016-08-25 00:13:01
您只需要使用text()和arrows()即可。考虑一下:
text(x=0.7, y=1.5, labels="(-E)", adj=c(.5,.5))
text(x=3.1, y=1.5, labels="(+E)", adj=c(.5,.5))
arrows(x0=1.4, x1=2.9, y0=1.5, code=1, angle=90, length=.1)
arrows(x0=3.3, x1=4.8, y0=1.5, code=2, angle=90, length=.1)

https://stackoverflow.com/questions/39128102
复制相似问题