0

试图在 R 中制作森林图。但我的并没有显示拂尘,这在森林图示例中很常见。另外我想摆脱情节底部的蓝色钻石。请对代码提出建议。代码运行但没有产生理想的结果。

下面是我的 R 代码

cochrane_from_rmeta <- 
  structure(list(
    mean  = c(NA, NA, 1.16, 1.18, 1.22, 1.24, 1.19, 1.17, 1.14, 1.28, NA), 
    lower = c(NA, NA, 1.14, 1.17, 1.20, 1.22, 1.18, 1.15, 1.13, 1.27, NA),
    upper = c(NA, NA, 1.16, 1.19, 1.23, 1.26, 1.21, 1.19, 1.15, 1.29, NA)),
    .Names = c("mean", "lower", "upper"), 
    row.names = c(NA, -11L), 
    class = "data.frame")

tabletext<-cbind(
  c("", "Disaster", "Frances", "Ivan", 
    "Katrina", "Wilma", "Rita", "Ike", 
    "Irene", "Sandy", ""),
  c("Hospitalization", "Exposure", "52,601", "74,511", 
    "20,966", "22,150", "20,964", "19,472", 
    "47,116", "58,963", NA),
  c("Hospitalization", "Non-exposure", "525,228", "730,144", 
    "197,795", "207,937", "203,007", "192,782", 
    "474,373", "541,190", NA),
  c("", "IRR", "1.16", "1.18", 
    "1.22", "1.24", "1.19", "1.17", 
    "1.14", "1.28", NA))

forestplot(tabletext, 
           cochrane_from_rmeta,new_page = TRUE,
           is.summary=c(TRUE,TRUE,rep(FALSE,8),TRUE),
           clip=c(0.9,2.5), 
           xlog=TRUE, 
           col=fpColors(box="royalblue",line="darkblue", summary="royalblue"))

结果是

在此处输入图像描述

4

2 回答 2

1

你原来的情节确实显示了搅拌器。因为你让 x 轴太大而看不到它们。我删除了clip=c(0.9,2.5).

library(forestplot)
cochrane_from_rmeta <- 
  structure(list(
    mean  = c(NA, NA, 1.16, 1.18, 1.22, 1.24, 1.19, 1.17, 1.14, 1.28, NA), 
    lower = c(NA, NA, 1.14, 1.17, 1.20, 1.22, 1.18, 1.15, 1.13, 1.27, NA),
    upper = c(NA, NA, 1.16, 1.19, 1.23, 1.26, 1.21, 1.19, 1.15, 1.29, NA)),
    .Names = c("mean", "lower", "upper"), 
    row.names = c(NA, -11L), 
    class = "data.frame")

tabletext<-cbind(
  c("", "Disaster", "Frances", "Ivan", 
    "Katrina", "Wilma", "Rita", "Ike", 
    "Irene", "Sandy", ""),
  c("Hospitalization", "Exposure", "52,601", "74,511", 
    "20,966", "22,150", "20,964", "19,472", 
    "47,116", "58,963", NA),
  c("Hospitalization", "Non-exposure", "525,228", "730,144", 
    "197,795", "207,937", "203,007", "192,782", 
    "474,373", "541,190", NA),
  c("", "IRR", "1.16", "1.18", 
    "1.22", "1.24", "1.19", "1.17", 
    "1.14", "1.28", NA))

forestplot(tabletext, 
       cochrane_from_rmeta,new_page = TRUE,
       is.summary=c(TRUE,TRUE,rep(FALSE,8),TRUE),
     #  clip=c(0.9,2.5), # not working
       xlog=TRUE, 
       col=fpColors(box="royalblue",line="darkblue"))

在此处输入图像描述

于 2019-09-13T21:59:36.717 回答
0

在绘制森林图之前,您应该打开一个具有足够宽度的窗口。
如果您在 Windows 机器上,请尝试例如:

windows(12,5)
p <- forestplot(tabletext, 
                cochrane_from_rmeta, new_page=TRUE,
                is.summary=c(TRUE, TRUE, rep(FALSE,8), TRUE),
                xlog=T, col=fpColors(box="royalblue",line="darkblue", summary="royalblue"))

在此处输入图像描述

于 2019-09-13T21:57:50.483 回答