R:森林图-图上的置信区间

时间:2019-05-03 15:44:29

标签: r visualization forestplot

我有一个代码可以可视化森林图。该代码包含针对森林图的多元回归分析和美学的数据:

library(forestplot)

names <- c("Variable", 
           "Year of the studies \u2265 4",
           "Faculty: medicine***",
           "Family doctor recommendation*",
           "Specialist doctor recommendation***",
           "Friend recommendation*")

coef2 <- c(1.30,1.89,1.82,4.03,0.58)
high2 <-c(0.92, 1.33, 1.05, 2.15, 0.38)
low2 <-c(1.83, 2.68, 3.14,7.54,0.90)
boxsize2 <- c(0.2,0.2,0.2,0.2,0.2)
test_data <- data.frame(coef=coef2, low=low2,high=high2,           boxsize=boxsize2)
test_data <- rbind(NA,  test_data)

row_names <-cbind(names, c("OR [95%CI]", "1.30 [0.92-1.84]", "1.89 [1.33-2.68]", "1.82 [1.05-3.14]", "4.03 [2.15-7.54]", "0.58 [0.38-0.90]"))

#####FIGURE
forestplot(labeltext = row_names,
           mean = test_data$coef, upper = test_data$high,
           lower = test_data$low,
           is.summary=c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE),
           boxsize = test_data$boxsize,
           zero = 1,
           xlog = FALSE,
           xlab = "OR (95% CI)",
           col = fpColors(lines="black", box="black"),
           ci.vertices = TRUE,
           xticks = c(0, 1, 2.5, 5,7.5),
           colgap = unit(0.03,'npc'),
           hrzl_lines= TRUE,
           lineheight = unit(1.1,"cm"),
           graphwidth = "auto",
           txt_gp=fpTxtGp(label = gpar(cex = 0.8),
                          title = gpar(cex = 1),
                          ticks = gpar(cex = 0.7),
                          xlab = gpar(cex = 0.7)))

生成的图: enter image description here

但是,我无法生成置信区间。我应该改变些什么以可视化置信区间?

1 个答案:

答案 0 :(得分:0)

我发现了问题。只需更改向量的名称即可:

low2 <-c(0.92, 1.33, 1.05, 2.15, 0.38)
high2 <-c(1.83, 2.68, 3.14,7.54,0.90)

enter image description here