Unable to expand plot region in forest()
Closed this issue · 2 comments
Classification:
Feature Request
Summary
Please could you include the functionality to increase the width of the plot region on the x axis in the forest() function. I have tried to adjust this by accessing the underlying axis function but no change seem to take effect.
Reproducible Example (if applicable)
library(metafor)
### meta-analysis of the log risk ratios using a random-effects model
res <- rma(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg,
slab=paste(author, year, sep=", "))
### default forest plot of the log risk ratios and summary estimate
forest(res, header=TRUE)
### summary estimate in row -1; studies in rows k=13 through 1; horizontal
### lines in rows 0 and k+1; two extra lines of space at the top for headings,
### and other annotations; headings (if requested) in line k+2
op <- par(xpd=TRUE)
text(x=-8.4, y=-1:16, -1:16, pos=4, cex=.6)
par(op)
### can also inspect defaults chosen
defaults <- forest(res)
defaults
### several forest plots illustrating the use of various arguments
forest(res, cex=.8)
forest(res, xaxp=c(10, 50, 2), cex=.8)
# No change!
Notes
For context, this is the actual plot I am working with. I am not able to post it as a reproducible example as it is not published yet.
forest(res_pos_mix_adj,
#xaxp=c(-10, 2, 1),
cex.lab = 10,
# annotate = FALSE, # whether annotations should be added (default = TRUE)
showweights = TRUE, # whether annotations should include inverse variance weights (default = FALSE)
# header = TRUE, # whether column headings should be added (default = FALSE)
xlim = c(-20, 2), # horizontal limits of the plot region
alim = c(-1,1), # x-axis limits
ylim = c(-0.5, 33), # y-axis limits
at = c(-1, -0.5, 0, 0.5, 1), # position of the x-axis tick marks and corresponding labels
steps = 5, # the number of tick marks for the x-axis (default = 5)
refline = 0, # numeric value to specify the location of the vertical reference line (default = 0)
digits = 1, # integer to specify the number of decimal places for the tick mark labels
width = 1, # manually adjust the width of the columns for the annotations
xlab = "", # title for the x-axis
slab = NA, # optional vector with labels for the k studies
ilab=cbind(gsub("[(]", " et al., (", data_pos_mix$reference),
mgsub::mgsub(data_pos_mix$cohort_short, c("; Females", "; Males"), c(" (F)", " (M)")),
data_pos_mix$risk_factor_short,
data_pos_mix$dbd_short), # optional vector, matrix or data frame providing additional information about the studies
ilab.xpos = c(-20, -14.5, -12.5, -8), # numeric vector to specify the horizontal position of the variables given via ilab
ilab.pos = 4, # integers to specify the alignment of the vectors given via ilab (2 = right, 4 = left aligned)
textpos = c(-20, -3),
order = data_pos_mix$rob_cat, # how studies should be ordered
pch = 17, # plotting symbol for use for the observed outcomes (default = square)
# psize = , # point sizes for the observed outcome
# plim = , # scale the point sizes
colout = "slateblue2", # specify the color to use for plotting the observed outcomes
col = "slateblue2", # specify the color to use for the summary polygon or fitted values
border = "slateblue2", # specify the color to use for the border of the summary polygon or fitted values
# lty = "blank", # line type for the confidence intervals
fonts = "Arial", # specify the font for the study labels, annotations etc
cex = .75 # expansion factor
# cex.lab = , # expansion for x-axis title
# cex.axis = , # expansion for x-axis labels
)
op <- par(cex = 0.75, font = 2)
text(c(-20, -14.5, -12.5, -8), res_pos_mix_adj$k+2, c("Reference", "Cohort", "Risk Factor", "Outcome", "Risk of bias"))
par(op)
dev.off()
sessionInfo()
Post output of sessionInfo()
below:
R version 4.1.0 (2021-05-18)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS 12.6
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] metafor_3.5-13 metadat_1.2-0 Matrix_1.4-1
loaded via a namespace (and not attached):
[1] compiler_4.1.0 tools_4.1.0 mathjaxr_1.6-0 nlme_3.1-157 grid_4.1.0 lattice_0.20-45
I am not sure what you expect xaxp
to do here. You can control the x-axis limits via alim
and the number of tick marks in between the lower and upper limits via steps
or use at
to directly specify the exact location. You also might need to play around with xlim
to create more/less space for the area in the plot that is used for drawing the points/CI bounds. The actual size of the plot cannot be controlled via the function; that is controlled by the size of the plotting device.