1

我已经制作了一个森林图,并且希望将带有胡须的正方形设为所有负数估计值,并且所有正数都应保持蓝色。这可能吗?

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 的正方形和须线应该是红色的。情节的其余部分应保持不变。

4

1 回答 1

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, ...)
           })

请注意,foresplot 不会返回任何有用的信息。我应该返回一个带有相关绘图/打印的 grob,但在设计包时我没有意识到。

于 2020-03-08T18:20:12.243 回答