2014-11-03 124 views
2

我會在打印日誌的紙張上添加兩個箭頭。下面是從metafor::forest演示圖:如何將箭頭添加到林地?

require(metafor) 
data(dat.bcg) 
res <- rma(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg, 
      slab=paste(author, year, sep=", ")) 
forest(res, cex=.8, order=order(dat.bcg$ablat), addfit=F) 

我要的是添加沿x軸的兩個箭頭諸如此類(紅色框): enter image description here

是否有人知道該怎麼辦呢?

回答

2

其中一個想法是使用layout將您的繪圖分爲兩部分,並用新繪圖代替x軸標籤。

enter image description here

## define the layout matrix 
## 2 rows and 3 columns , the rectangle will be in the cell(2,2) 
layout(matrix(c(1,1,1,0,2,0), 2, 3, byrow = TRUE), 
     heights=c(3,1),widths=c(1,2,1)) 
## define the margin since the default ones are usually not enough 
par(mar = rep(2, 4)) 

## your plot here 
data(dat.bcg) 
res <- rma(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg, 
      slab=paste(author, year, sep=", ")) 
forest(res, cex=.8, order=order(dat.bcg$ablat), addfit=F,xlab='') 

## here all the job 
x <- y <- 2:8 
## dummy plot to define scales 
plot(x,y,type='n',axes=F,xlab='',ylab='') 
## rectangle 
rect(2,4,8,8,border='red') 
## arrows 
arrows(5.5,6,7,6) 
arrows(4.5,6,3,6) 
text(6,6,'A better',adj=c(0,1.5),col='blue') 
text(3.5,6,'B better',adj=c(0,1.5),col='green') 
## x label 
text(5,3,'Risk Difference',cex=2) 
+0

謝謝,@agstudy。紅色矩形不是情節的一部分,只是一個指標:D。 – 2014-11-03 19:29:38

+0

@DavidZ :)我喜歡它!我會保留在我的答案! – agstudy 2014-11-03 19:31:10