[R-meta] modifying the default forest plot
Viechtbauer Wolfgang (SP)
wolfgang.viechtbauer at maastrichtuniversity.nl
Wed Dec 6 00:06:07 CET 2017
Please always cc the list.
As for adjusting the arrangement of the various elements in the plot, you have two options:
1) Make the plotting device wider. I don't know how you are creating the plot, but if you are doing this 'interactively', you can just do this by increasing the width of the window for the plot. If you are using something like png(), pdf(), or some other plotting device to save the plot, then you adjust the 'width' argument.
2) You can also play around with the 'xlim' argument. First do this:
print(forest(random13, showweights=TRUE, xlab='Estimated Effect Size', order="obs", slab=paste(play1$author, play1$year, sep=", ")))
Note the default value for 'xlim'. Then rerun the forest() command as above (without the print()) but adjust 'xlim', that is, use xlim=c(lower, upper). Increase/decrease the lower and upper values to see how this affects the plot.
To label elements, use text(). For example:
text(lower, 15, "Author(s) and Year", pos=4)
text(upper, 15, "ES [95% CI]", pos=2)
where lower/upper are the values you specified for xlim and you need to adjust the '15' depending on how many rows are in your forest plot (the second value of text() determines the y coordinate where the text is written). You can use text() to also add a label for the weights.
You might also want to go through the examples at the end of help(forest.rma) to get an idea of what can be done.
Best,
Wolfgang
-----Original Message-----
From: Mukht Kaur [mailto:theoneliberatedkaur at gmail.com]
Sent: Tuesday, 05 December, 2017 23:31
To: Viechtbauer Wolfgang (SP)
Subject: Re: [R-meta] modifying the default forest plot
Thank you guys! So I successfully made edits to my default forest plot using
forest (random13, showweights=TRUE, xlab='Estimated Effect Size', order="obs", slab=paste(play1$author, play1$year, sep=", "))
The weights assigned are represented in the figure but they seem too close to the CIs. Is there a way to label them and CIs? I looked at other arguments which can be used for the 'forest' function. None seem applicable to the labelling I intend to do. Any ideas?
On Tue, Dec 5, 2017 at 4:58 AM, Viechtbauer Wolfgang (SP) <wolfgang.viechtbauer at maastrichtuniversity.nl> wrote:
Ken already gave some pointers.
1) How could I get the author and year instead?
Use the 'slab' argument. For example:
slab=paste(dat$author, dat$year, sep=", "))
(assuming that there are 'author' and 'year' variables in the data frame 'dat').
2) It would be better if I can get them arranged according to the observed effect size - is that possible?
Use argument: order="obs"
3) Also, I would like to change the title of my X axis to 'Estimated Effect Size'
rather than the default title 'Observed Outcome'.
Use argument: xlab="Estimated Effect Size"
4) Lastly, would it be possible to specify the exact weight assigned to each study in the forest plot?
Use argument: showweights=TRUE
Best,
Wolfgang
-----Original Message-----
From: R-sig-meta-analysis [mailto:r-sig-meta-analysis-bounces at r-project.org] On Behalf Of Mukht Kaur
Sent: Tuesday, 05 December, 2017 6:30
To: r-sig-meta-analysis at r-project.org
Subject: [R-meta] modifying the default forest plot
Hi everyone!
I am new to meta-analysis methodology and I am using R software to do my
quantitative synthesis. I am using random effects model to analyse my
individual studies through rma function in metafor package.
By using 'forest(mymodelname)', I have a basic forest plot where my
individual studies are shown as Study 1, Study 2, and so on. How could I
get the author and year instead? It would be better if I can get them
arranged according to the observed effect size - is that possible? Also, I
would like to change the title of my X axis to 'Estimated Effect Size'
rather than the default title 'Observed Outcome'. Lastly, would it be
possible to specify the exact weight assigned to each study in the forest
plot?
Many thanks in advance for your help.
MK
More information about the R-sig-meta-analysis
mailing list