在 forestplot R 中指定连续对数转换 x 轴的限制

Specifying limits of a continuous log-transformed x-axis in forestplot R

我正在尝试将数据绘制到具有对数转换的连续 x 轴的图形上。我的代码如下:

(森林图的样本数据)

    tabletext <- cbind(c("Analysis","combined","A","B"),
    c("Observational","0.92 [0.87,0.96]","0.94 [0.89,1.01]","0.88 [0.82,0.95]"),
    c("MR","0.95 [0.92,0.98]","0.96 [0.92,1.00]","0.87 [0.78,0.97]")) 
    mean_mr <- c(NA,0.95,0.96,0.84)
    mean_obs <- c(NA,0.92,0.94,0.85)
    lower_mr <- c(NA,0.92,0.92,0.78)
    lower_obs <- c(NA,0.87,0.89,0.82) 
    upper_mr <- c(NA, 0.98,1.00,0.97)
    upper_obs <- c(NA,0.96,1.10,0.94)

    mean <- cbind(mean_obs,mean_mr)
    lower <- cbind(lower_obs,lower_mr)
    upper <- cbind(upper_obs,upper_mr)

生成森林图:

    library(forestplot)

    forestplot(tabletext,mean,lower,upper,is.summary=c(TRUE,rep(FALSE,3)),
       boxsize=0.2,hrzl_lines=gpar(lwd=1,columns=1:4),xlog=1,
       col=fpColors(box=c("black"),line=c("black")),
       txt_gp = fpTxtGp(label = gpar(fontfamily = "",cex=1.1), 
       ticks=gpar(fontfamily="",cex=0.8),xlab  = gpar(fontfamily = "", cex = 1.1)))

我试过使用 xlim 指定 x 轴限制,但这对绘图没有影响,而且 xticks 似乎覆盖了 xlog 参数。我还注意到,即使我删除了 xlog 参数,我也无法指定 x 轴限制。有什么方法可以在 forestplot 的(对数转换的)尺度上指定 x 轴限制?

你有哪个forestplot版本? 我在 help page 上找到了这条注释:

"Note: An important difference from the original forestplot is that the current function interprets xlog as the x-axis being in log-format, i.e. you need to provide the data in the antilog/exp format."。据我了解,xlog 只是在 1 而不是 0 处画线。

如果我 运行 你的例子

  forestplot(tabletext,mean,lower,upper,is.summary=c(TRUE,rep(FALSE,3)),
           boxsize=0.2,hrzl_lines=gpar(lwd=1,columns=1:4), xlog=1,
           col=fpColors(box=c("black"),line=c("black")),
           txt_gp = fpTxtGp(label = gpar(fontfamily = "",cex=1.1), 
                            ticks=gpar(fontfamily="",cex=0.8),xlab  = gpar(fontfamily = "", cex = 1.1)),
          xticks = c(0.4, 0.77, 0.9, 1)
          )

输出是

-> 限制和 xticks 都改变了。

好像"clip"习惯了"Lower and upper limits for clipping confidence intervals to arrows"(根据the forestplot package)。

您可以将此粘贴到您的代码中:clip(c(下限值,上限值))。 例如,在您的代码中,我将下限设置为 0.8,将上限设置为 1.2:

forestplot(tabletext,mean,lower,upper,is.summary=c(TRUE,rep(FALSE,3)), clip(c(0.8, 1.2))
       boxsize=0.2,hrzl_lines=gpar(lwd=1,columns=1:4),xlog=1,
       col=fpColors(box=c("black"),line=c("black")),
       txt_gp = fpTxtGp(label = gpar(fontfamily = "",cex=1.1), 
       ticks=gpar(fontfamily="",cex=0.8),xlab  = gpar(fontfamily = "", cex = 1.1)))

output plot image

奇怪的是下限不会改变,但上限得到了扩展,因此 xticks 不再覆盖 xlog 参数。希望这有效!