I'm new to R. Any help would be welcome!
Minimum reproducible example:
library(metafor)
base_data <- tibble::tibble(OR = c(0.87, 0.93, 0.93, 0.97, 1.03, 1, 1.02, 0.99),
ci.ub = c(3.12, 3.38, 3.39, 3.57, 1.58, 1.54, 1.56, 1.51),
ci.lb = c(0.24, 0.26, 0.26, 0.26, 0.68, 0.65, 0.67, 0.64),
study = c("ITT", "PP", "ITT", "PP",
"ITT", "PP", "ITT", "PP"))
with(base_data, forest(OR, ci.lb=ci.lb, ci.ub=ci.ub,
header = c("Study", "OR (95% CI)"),
xlab = "OR (95% CI)",
refline=1,
slab = study,
rows=c(1:2, 4:5, 7:8, 10:11),
atransf=exp,
alim=c(0.5,2),
ilab = cbind(c(6.3, 6.5, 6.4, 6.6, 0.9, 0.8, 0.9, 0.8), c(7.0, 7.0, 7.1, 7.1, 1.2, 1.2, 1.3, 1.3))))
par(font=2)
text(c(-0.7,-0.2), 13, c("Intervention", "Control"))
par(font=4)
text(-2.3,
c(11.5, 8.5, 5.5, 2.5),
pos=4,
c("Model 1", "Model 2", "Model 3", "Model 4")
)
I would like to change the scale of the xaxis to a log scale with limits from 0.5-2.0 and with the CIs clipped beyond those limits.
Thanks!
I tried
atransf=exp
but it didn't work properly and anything I try messes with the clipping of the CIs.
Your dataset already includes the odds ratios and corresponding CI bounds, so using
atransf=expdoesn't make sense. However, it does if you log transform the values, so start your forest plot with:and then use
alim=log(c(0.5,2))or theatargument if you want more control over the exact position of the ticks (e.g.,at=log(c(0.5,1,2))).You might have to play around with
xlimand maybeilab.xposto arrange things in a nicer way. Theforest()functions actually return some of the default values that are chosen, so you can inspect what they are and use them as starting points to arrange things exactly as you like.