1

没有图例,我的森林图使用下面的代码运行良好

rm(list=ls())
library(forestplot)

test_data2<-data.frame(prev1=c(0, 70, NA), 
                   prev0=c(0, 20, NA), 
                   prev3=c(NA,NA , 30),
                   prev4=c(NA,NA , 30),
                   low1=c( 0, 30, NA), 
                   low0=c( 0, 10, NA), 
                   low3=c(NA, NA, 10),
                   low4=c(NA, NA, 10),
                   high1=c( 30, 90, NA), 
                   high0=c( 20, 50, NA),
                   high3=c(NA,NA , 60),
                  high4=c(NA,NA , 60))

test_data2 <- rbind(rep(NA, 3), test_data2)

col_no2<-grep("prev", colnames(test_data2))

row_names2<-list(
list("Author", "You", "Asiimwe", "Martin"), 
list("Year", "1988", "1984", "1964")
)


prev<-with(test_data2, cbind(prev1, prev0, prev3, prev4))
low<-with(test_data2, cbind(low1, low0, low3, low4))
high <- with(test_data2, cbind(high1, high0, high3, high4))

forestplot(row_names2, prev, low, high,
       #zero = c(0, 0.01),
       fn.ci_norm = list(list(fpDrawNormalCI, fpDrawCircleCI,       fpDrawDiamondCI, fpDrawPointCI),
                         list(fpDrawNormalCI, fpDrawCircleCI, fpDrawDiamondCI, fpDrawPointCI),
                         list(fpDrawNormalCI, fpDrawCircleCI, fpDrawDiamondCI, fpDrawPointCI),
                         list(fpDrawNormalCI, fpDrawCircleCI, fpDrawDiamondCI, fpDrawPointCI)
                         ),

       xticks = c(0,10, 20, 30, 40, 50, 60, 70, 80, 90, 100),
       txt_gp = fpTxtGp(label = list(gpar(fontfamily = ""),
                                     gpar(fontfamily = "",
                                          col = "black")),
                        ticks = gpar(fontfamily = "", cex=0.8),
                        xlab  = gpar(fontfamily = "", cex = 0.8)),
       boxsize=0.15,
       line.margin = .1, # We need to add this to avoid crowding
       lty.ci = c(1, 2, 3, 4),
       xlab="Prevalence (%)",
       new_page = TRUE)

但是,当我用 CI 为每个 prev1、prev2、prev3 和 prev4 放置图例时,出现了错误并且它不起作用。

我使用的代码如下所示。

rm(list=ls())
library(forestplot)

test_data2<-data.frame(prev1=c(0, 70, NA), 
                   prev0=c(0, 20, NA), 
                   prev3=c(NA,NA , 30),
                   prev4=c(NA,NA , 30),
                   low1=c( 0, 30, NA), 
                   low0=c( 0, 10, NA), 
                   low3=c(NA, NA, 10),
                   low4=c(NA, NA, 10),
                   high1=c( 30, 90, NA), 
                   high0=c( 20, 50, NA),
                   high3=c(NA,NA , 60),
                  high4=c(NA,NA , 60))

test_data2 <- rbind(rep(NA, 3), test_data2)

col_no2<-grep("prev", colnames(test_data2))

row_names2<-list(
list("Author", "You", "Asiimwe", "Martin"), 
list("Year", "1988", "1984", "1964")
)


prev<-with(test_data2, cbind(prev1, prev0, prev3, prev4))
low<-with(test_data2, cbind(low1, low0, low3, low4))
high <- with(test_data2, cbind(high1, high0, high3, high4))

forestplot(row_names2, prev, low, high,
       #zero = c(0, 0.01),
       fn.ci_norm = list(list(fpDrawNormalCI, fpDrawCircleCI,       fpDrawDiamondCI, fpDrawPointCI),
                         list(fpDrawNormalCI, fpDrawCircleCI, fpDrawDiamondCI, fpDrawPointCI),
                         list(fpDrawNormalCI, fpDrawCircleCI, fpDrawDiamondCI, fpDrawPointCI),
                         list(fpDrawNormalCI, fpDrawCircleCI, fpDrawDiamondCI, fpDrawPointCI)
                         ),

       xticks = c(0,10, 20, 30, 40, 50, 60, 70, 80, 90, 100),
       txt_gp = fpTxtGp(label = list(gpar(fontfamily = ""),
                                     gpar(fontfamily = "",
                                          col = "black")),
                        ticks = gpar(fontfamily = "", cex=0.8),
                        xlab  = gpar(fontfamily = "", cex = 0.8)),
       boxsize=0.15,
       line.margin = .1, # We need to add this to avoid crowding
       lty.ci = c(1, 2, 3, 4),
       xlab="Prevalence (%)",
       new_page = TRUE,
       legend=c("HIV-infected", "HIV-uninfected", "All participats", "Love-you"),
       legend_args = fpLegend(pos = list("topright"),
                              r = unit(.1, "snpc")  
                              ))

有人对此有任何想法吗?谢谢!

4

1 回答 1

0

事实证明这是一个错误 - 感谢允许快速调试的详尽报告。应该在 1.7.1 开发版本中修复,使用安装它devtools

devtools::install_github("gforge/forestplot", ref="develop")
于 2017-04-12T06:50:41.130 回答