将分组线添加到R

时间:2016-08-24 16:03:24

标签: r graphics

我使用以下代码创建了一个条形图:

#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")

看起来像这样:

enter image description here

我想在图的顶部空白处添加一些标签,以指示是否存在治疗E。第一个栏是(-E),栏2-4是(+E)。我希望结果看起来像这幅画: enter image description here

我怎样才能在基地R中这样做?

1 个答案:

答案 0 :(得分:1)

您只需使用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) 即可。考虑一下:

library(raster)  
x <- mean(14.68,15.16)  
y <- mean(54.987,55.299)
temp <- brick("tas_decreg_europe_v20140120_20030101_20030131.nc", var='tas')
extract(temp, cbind(x,y))

enter image description here