Jus*_*ted 3 expression r scientific-notation r-forestplot metafor
所以我正在使用meta.for包进行荟萃分析R.我正准备在科学期刊上发表数据,我想在我的森林地块中添加p值,但科学注释格式为
x10-04Run Code Online (Sandbox Code Playgroud) 而不是标准
e-04
然而,争论ilab的forest功能不接受expression一流的对象,但仅矢量
这是一个例子:
library(metafor)
data(dat.bcg)
## REM
res <- rma(ai = tpos, bi = tneg, ci = cpos, di = cneg, data = dat.bcg,
measure = "RR",
slab = paste(author, year, sep = ", "), method = "REML")
# MADE UP PVALUES
set.seed(513)
p.vals <- runif(nrow(dat.bcg), 1e-6,0.02)
# Format pvalues so only those bellow 0.01 are scientifically notated
p.vals <- ifelse(p.vals < 0.01,
format(p.vals,digits = 3,scientific = TRUE,trim = TRUE),
format(round(p.vals, 2), nsmall=2, trim=TRUE))
## Forest plot
forest(res, ilab = p.vals, ilab.xpos = 3, order = "obs", xlab = "Relative Risk")
Run Code Online (Sandbox Code Playgroud)
我希望将p值的科学记数法格式化为
x10-04Run Code Online (Sandbox Code Playgroud)
我见过的类似问题的所有答案都建议使用,expression()但这给出Error in cbind(ilab) : cannot create a matrix from type 'expression'了有意义,因为帮助文件forest指定ilab参数应该是一个向量.
关于如何解决这个问题或解决它的任何想法?
一个hacky解决方案是
forest.rma <- edit(forest.rma)
Run Code Online (Sandbox Code Playgroud)
转到第574行并进行更改
## line 574
text(ilab.xpos[l], rows, ilab[, l], pos = ilab.pos[l],
Run Code Online (Sandbox Code Playgroud)
至
text(ilab.xpos[l], rows, parse(text = ilab[, l]), pos = ilab.pos[l],
Run Code Online (Sandbox Code Playgroud)
修复你的p值和情节
p.vals <- gsub('e(.*)', '~x~10^{"\\1"}', p.vals)
forest(res, ilab = p.vals, ilab.xpos = 3, order = "obs", xlab = "Relative Risk")
Run Code Online (Sandbox Code Playgroud)