r语言 - 如何在森林图中分配不同的颜色的负面和正面影响



我做了一个森林图,想让所有负数的估计值的带有胡须的正方形变成红色,所有正数都应保持蓝色。这可能吗?

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

您只需在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, ...)
           })

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

相关内容

  • 没有找到相关文章

最新更新