我绘制了一个森林图,并希望将所有带有负数的估计的带有胡须的正方形设为红色,而所有正数应保持为蓝色。 这可能吗?
tabletext<-cbind(
c("","Intervention","1", "2", "3",
"4", "5", "6", "7",
"Baseline (ref)"),
c("","Predicted 95% CI","151 [128;175]", "146 [128;163]",
"161 [144;179]","147 [130;164]", "137 [121;154]","141 [126;156]",
"180[156;205 ]", "146 [129;162]"),
c("","p-value", ".98",".99", ".060",
".99", ".61",".92",".0016","ref"))
data <- data.frame(coef=c(NA,NA,6.093, 0.060,16.01,1.142,-8.42,-4.58, 34.45,0),
low=c(NA,NA,-12.4,-9.02,3.55,-9.82,-20.65,-15.16,15.97,0), high=c(NA,NA,24.62,9.14,28.464,12.11,3.80, 5.99, 52.92,0))
forest<-forestplot(tabletext,
upper = data$high,
lower=data$low,
mean = data$coef,
zero = 0,
boxsize = 0.2,
cex=0.9,
lineheight = "auto",
title="TITLE",
xlab = "Effect size 95% CI",
vertices = TRUE,
col=fpColors(box="darkblue", lines="darkblue", zero = "gray50"),
txt_gp=fpTxtGp(label=gpar(cex=1),
ticks=gpar(cex=1),
xlab=gpar(cex = 1),
title=gpar(cex = 1)))
因此,在这种情况下,因子5 + 6的正方形和胡须应为红色。其余的情节应该保持不变。
答案 0 :(得分:0)
您只需在fn.ci_norm
/ fn.ci_sum
周围添加包装即可:
forestplot(tabletext,
upper = data$high,
lower=data$low,
mean = data$coef,
zero = 0,
boxsize = 0.2,
cex=0.9,
lineheight = "auto",
title="TITLE",
xlab = "Effect size 95% CI",
vertices = TRUE,
col=fpColors(box="darkblue", lines="darkblue", zero = "gray50"),
txt_gp=fpTxtGp(label=gpar(cex=1),
ticks=gpar(cex=1),
xlab=gpar(cex = 1),
title=gpar(cex = 1)),
fn.ci_norm = function(estimate, clr.marker, ...) {
if (estimate < 0) {
clr.marker="darkred"
}
fpDrawNormalCI(clr.marker = clr.marker, estimate = estimate, ...)
})
请注意,前瞻不会返回任何有用的信息。我本该返回一个带有相关图样/打印件的文件,但是在设计程序包时却没有意识到。