如何向森林图添加箭头? [英] How to add arrows to a forest plot?

查看:265
本文介绍了如何向森林图添加箭头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会在森林图上添加两个箭头,用于发表期刊论文.这是来自 metafor::forest 的演示图:

I'd add two arrows to a forest plot for a paper going to a journal. Here is a demo plot from 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 轴添加两个箭头,例如(在红色框中):

what I want is to add two arrows along x axis such like(in red box):

有人知道怎么做吗?

推荐答案

一个想法是使用 layout 将您的绘图分成 2 部分,并用新绘图替换 x 轴标签.

One idea is to use layout to divide your plot in 2 parts and replace the x axis label by a new plot.

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

这篇关于如何向森林图添加箭头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆