我想用几年前script创建的Thomas来绘制森林图。不幸的是,脚本适合数据,如果治疗估计和置信区间不同,则需要对其进行调整。
使脚本适应我的数据
但是如您所见,x轴应该是对数转换的。但是,当我将log="x"
添加到plot()
函数时,出现以下错误消息:Error in plot.window(...) : Logarithmic axis must have positive limits
。
但是,如果我将xlim从xlim=c(-10,12)
更改为xlim=c(1,12)
,则创建的图不适合面板。此外,图左侧的每个文本x位置都需要负值。
有谁知道如何解决这个问题?
mydf <- data.frame(
SubgroupH=c('LV-EF',NA,NA,'Sex',NA,NA),
Subgroup=c(NA,'low','normal',NA,'female','male'),
NoOfPatients=c(NA,2815,1935,NA,3843,908),
HazardRatio=c(NA,1.07, 2.81,NA,1.69, 1.74),
HazardLower=c(NA,0.42, 1.26,NA,0.41, 0.96),
HazardUpper=c(NA,2.73, 6.26,NA,6.93, 3.16),
Pvalue=c(NA,0.77,0.17,NA,0.47,0.21),
PvalueI=c(0.46,NA,NA,0.46,NA,NA),
stringsAsFactors=FALSE
)
#################
rowseq <- seq(nrow(mydf),1)
par(mai=c(1,0,0,0))
plot(mydf$HazardRatio, rowseq, pch=15,
xlim=c(-10,12), ylim=c(0,7),
xlab='', ylab='', yaxt='n', xaxt='n',
bty='n')
axis(1, round(c(1/10, 1/5, 1, 5, 10),2), cex.axis=.5)
segments(1,-1,1,6.25, lty=3)
segments(mydf$HazardLower, rowseq, mydf$HazardUpper, rowseq)
mtext('Off-Pump\nCABG Better',1, line=2.5, at=0, cex=.5, font=2)
mtext('On-Pump\nCABG Better',1.5, line=2.5, at=2, cex=.5, font=2)
?text
text(-8,6.5, "Subgroup", cex=.75, font=2, pos=4)
t1h <- ifelse(!is.na(mydf$SubgroupH), mydf$SubgroupH, '')
text(-8,rowseq, t1h, cex=.75, pos=4, font=3)
t1 <- ifelse(!is.na(mydf$Subgroup), mydf$Subgroup, '')
text(-7.5,rowseq, t1, cex=.75, pos=4)
text(-5,6.5, "No. of\nPatients", cex=.75, font=2, pos=4)
t2 <- ifelse(!is.na(mydf$NoOfPatients), format(mydf$NoOfPatients,big.mark=","), '')
text(-3, rowseq, t2, cex=.75, pos=2)
text(-1,6.5, "Hazard Ratio (95%)", cex=.75, font=2, pos=4)
t3 <- ifelse(!is.na(mydf$HazardRatio), with(mydf, paste(HazardRatio,' (',HazardLower,'-',HazardUpper,')',sep='')), '')
text(3,rowseq, t3, cex=.75, pos=4)
text(7.5,6.5, "P Value", cex=.75, font=2, pos=4)
t4 <- ifelse(!is.na(mydf$Pvalue), mydf$Pvalue, '')
text(7.5,rowseq, t4, cex=.75, pos=4)
text(10,6.5, "P Value for\nInteraction", cex=.75, font=2, pos=4)
t5 <- ifelse(!is.na(mydf$PvalueI), mydf$PvalueI, '')
text(10,rowseq, t5, cex=.75, pos=4)