【发布时间】:2020-08-17 08:35:39
【问题描述】:
我正在使用 foresplot 包。我想创建一个包含两组(飞机、汽车)和每个组三个变量的森林图。我试图为箱线图和线条创建一个函数。但是,森林图表格文本有效,但函数无效。
示例数据
structure(list(X = c("Aeroplanes", "Sex (F)", "1", "2", "Cars",
"Sex (F)", "1", "2"), OR = c(NA, 1.35, 7.81, 6.14, NA, 1.17,
0.15, 0.4), Cl.low = c(NA, 1.13, 5.69, 4.36, NA, 0.74, 0.05,
0.16), CI.high = c(NA, 1.61, 11.01, 8.83, NA, 1.88, 0.35, 0.89
), p.value = c("", "< 0.001", "< 0.001", "< 0.001", "", "0.509",
"< 0.001", "0.034")), class = "data.frame", row.names = c(NA,
-8L))
CI <- table2OR_ed
CI <- within (CI, rm(X,OR, p.value))
CI$CI <-apply(CI,1,function(x){
paste0("(",paste(x, collapse=", "),")")
})
CI$CI[which(CI$CI=="(NA, NA)")] <- NA
tabletext <- cbind(c("Transport","\n",table2OR_ex$X),
c("Odds ratio","\n",table2OR_ex$OR),
c("Confidence Interval","\n",CI$CI))
fn <- local({
i = 0
no_lines <- sum(!is.na(table2OR_ex$OR))
b_clrs = colorRampPalette(colors=c("pink", "blue"))(no_lines)
l_clrs = colorRampPalette(colors=c("blue", "pink"))(no_lines)
function(..., clr.line, clr.marker){
i <<- i + 1
fpDrawDiamondCI(..., clr.line = l_clrs[i], clr.marker = b_clrs[i])
}
})
forestplot(labeltext=tabletext, graphwidth=unit (70, "mm"), graph.pos=3,
mean=c(NA,NA,table2OR_ex$OR),
lower=c(NA,NA,table2OR_ex$CI.low), upper=c(NA,NA,table2OR_ex$CI.high),
fn.ci_norm = fn, #use function
txt_gp=fpTxtGp(label=gpar(fontsize=12, cex=1),
ticks=gpar(fontsize=12, cex=1.4),
xlab=gpar(fontsize=12,cex = 1),
title=gpar(fontsize=12,cex = 1.2)),
zero=1,boxsize=0.4)
我收到此错误
警告信息: 在 min(lower, na.rm = TRUE) 中: min 没有不可缺少的参数;返回Inf
我检查了类并且 CI.low 为空,即使在我导入 csv 时它是数字。那么也许这是错误的根源?
【问题讨论】:
-
CI.low有两种不同的拼写形式 -
@rawr 抱歉,我错过了 CI 的一些代码
标签: r forestplot