森林情节与边桌不符

时间:2015-09-17 23:18:53

标签: r forestplot

我必须做一个森林情节和边桌,但不是使用优势比(像往常一样),我必须使用效果大小。我根据我在互联网上发现的另一个代码编写了这段代码,因为我需要使用forestplot和sidetable。我编辑了我的问题以包含示例数据和我的部分解决方案。

library(forestplot)


####With this I create the data for the tabletext###
TE<-as.character(c(-0.05, 0.27, 0.39, 0.21, 0, 0.08, 0.28, 0.23, -0.16, 0.11, 0.13,
                 0.03, 0.78, 0.43, 0.07, 0.34, 0.58))
Inferior<-as.character(c(-0.55, -0.22, -0.11, -0.3, -0.31, -0.22, -0.03, -0.07, -0.47,
                       -0.19, -0.18, -0.27, 0.46, 0.12, -0.55, -0.07, 0.15))
Superior<-as.character(c(0.44, 0.76, 0.88, 0.73, 0.31, 0.39, 0.6, 0.54, 0.15, 0.42, 
                         0.45, 0.34, 1.11, 0.74, 0.69, 0.75, 1.02))
Autor<-c("Cain & Smith", "Cain & Smith", "Cain & Smith", "Cain & Smith", 
         "Hoffman & Dangl", "Hoffman & Dangl", "Hoffman & Dangl", "Hoffman & Dangl",
         "Hoffman & Dangl", "Hoffman & Dangl", "Hoffman & Dangl", "Hoffman & Dangl",
         "Hoffman & Dangl", "Hoffman & Dangl", "Bunch", "Bunch", "Bunch")

###With this I create the values for the forest plot###
TE2<-c(NA, -0.05, 0.27, 0.39, 0.21, 0, 0.08, 0.28, 0.23, -0.16, 0.11, 0.13,
       0.03, 0.78, 0.43, 0.07, 0.34, 0.58, NA, NA)
Inferior2<-c(NA, -0.55, -0.22, -0.11, -0.3, -0.31, -0.22, -0.03, -0.07, -0.47,
             -0.19, -0.18, -0.27, 0.46, 0.12, -0.55, -0.07, 0.15, NA, NA)
Superior2<-c(NA, 0.44, 0.76, 0.88, 0.73, 0.31, 0.39, 0.6, 0.54, 0.15, 0.42, 0.45,
             0.34, 1.11, 0.74, 0.69, 0.75, 1.02, NA, NA)

###With this I create the sidetable###
tabletext<-cbind(
  c("Autor", Autor, NA, "Summary"),
  c("Effect Size", TE, NA, NA),
  c("Inferior", Inferior, NA, NA),
  c("Superior", Superior, NA, "0.17"))

###With this I create the forestplot###
forestplot(tabletext, 
           hrzl_lines = gpar(col="#444444"),
           mean = TE2, lower = Inferior2, upper = Superior2, 
           new_page = TRUE,
           xlog=FALSE,
           is.summary=c(TRUE, rep(FALSE,18), TRUE),
           graph.pos=5,
           boxsize=0.2,
           col=fpColors(box="black",line="black", summary="black"))

我之前的问题是生成的林图会将效果大小向上移动一行(因此,它们与侧边栏上的信息不匹配,因为从列标题级别开始)。现在,我唯一的问题是它没有将摘要添加到情节中。

我真的很感谢你的帮助!

1 个答案:

答案 0 :(得分:1)

您的问题是您没有将摘要信息添加到平均值,上限和下限。置信区间较低:

library(forestplot)
####With this I create the data for the tabletext###
TE<-as.character(c(-0.05, 0.27, 0.39, 0.21, 0, 0.08, 0.28, 0.23, -0.16, 0.11, 0.13,
                   0.03, 0.78, 0.43, 0.07, 0.34, 0.58))
Inferior<-as.character(c(-0.55, -0.22, -0.11, -0.3, -0.31, -0.22, -0.03, -0.07, -0.47,
                         -0.19, -0.18, -0.27, 0.46, 0.12, -0.55, -0.07, 0.15))
Superior<-as.character(c(0.44, 0.76, 0.88, 0.73, 0.31, 0.39, 0.6, 0.54, 0.15, 0.42, 
                         0.45, 0.34, 1.11, 0.74, 0.69, 0.75, 1.02))
Autor<-c("Cain & Smith", "Cain & Smith", "Cain & Smith", "Cain & Smith", 
         "Hoffman & Dangl", "Hoffman & Dangl", "Hoffman & Dangl", "Hoffman & Dangl",
         "Hoffman & Dangl", "Hoffman & Dangl", "Hoffman & Dangl", "Hoffman & Dangl",
         "Hoffman & Dangl", "Hoffman & Dangl", "Bunch", "Bunch", "Bunch")

###With this I create the values for the forest plot###
TE2<-c(NA, -0.05, 0.27, 0.39, 0.21, 0, 0.08, 0.28, 0.23, -0.16, 0.11, 0.13,
       0.03, 0.78, 0.43, 0.07, 0.34, 0.58, NA, NA)
Inferior2<-c(NA, -0.55, -0.22, -0.11, -0.3, -0.31, -0.22, -0.03, -0.07, -0.47,
             -0.19, -0.18, -0.27, 0.46, 0.12, -0.55, -0.07, 0.15, NA, NA)
Superior2<-c(NA, 0.44, 0.76, 0.88, 0.73, 0.31, 0.39, 0.6, 0.54, 0.15, 0.42, 0.45,
             0.34, 1.11, 0.74, 0.69, 0.75, 1.02, NA, NA)

###With this I create the sidetable###
tabletext<-cbind(
  c("Autor", Autor, NA, "Summary"),
  c("Effect Size", TE, NA, NA),
  c("Inferior", Inferior, NA, NA),
  c("Superior", Superior, NA, "0.17"))

# Add this!
TE2[20] <- .17
Inferior2[20] <- TE2[20] - .3
Superior2[20] <- TE2[20] + .3

###With this I create the forestplot###
forestplot(tabletext, 
           hrzl_lines = gpar(col="#444444"),
           mean = TE2, lower = Inferior2, upper = Superior2, 
           new_page = TRUE,
           xlog=FALSE,
           is.summary=c(TRUE, rep(FALSE,18), TRUE),
           graph.pos=5,
           boxsize=0.2,
           col=fpColors(box="black",line="black", summary="black"))

enter image description here