[R-meta] Adding vertical space to forest.rma plot
Viechtbauer Wolfgang (SP)
wolfgang.viechtbauer at maastrichtuniversity.nl
Mon Oct 2 17:23:38 CEST 2017
Aside from this, how are you (James) actually saving the graphic (or importing it into your manuscript)? Are you using png(), tiff(), pdf(), or something like that? Then you just need to adjust the height of your plotting device to use less vertical space (e.g., see help(png) and the 'height' argument). I suspect though that you might be using the 'right click save as' approach -- which you really shouldn't (since this isn't a fully scripted and hence not a fully reproducible approach).
Best,
Wolfgang
-----Original Message-----
From: R-sig-meta-analysis [mailto:r-sig-meta-analysis-bounces at r-project.org] On Behalf Of Michael Dewey
Sent: Monday, 02 October, 2017 14:50
To: James Rae; r-sig-meta-analysis at r-project.org
Subject: Re: [R-meta] Adding vertical space to forest.rma plot
Dear James
Did you know that if you save the result of forest and inspect it you
will find some details about the parameters it used which can be very
helpful in tweaking the plot? The second paragraph in the Note part of
the documentation states this but it is quite easy to miss (in fact I
knew it was there but still failed to find it immediately). I am sorry I
cannot be more specific about exactly what you need to do here.
On 02/10/2017 12:03, James Rae wrote:
> Hello,
>
> I'm editing a proof for publication. The paper reports a meta-analysis of 5 studies I conducted, an analysis that I conducted using the metafor package in R. I then plotted by results using the "forest.rma" function.
>
> My problem is that the journal believes that the vertical alignment in the plot is inefficient. That is, there is too much white space between the study entries (and also the summary statistic that I report in the bottom of the plot). I've tried to change this by adjusting the "ylim" argument in the "forest.rma" function with no success. Do you know how I can make rows in the forest plot closer together and use the vertical space more efficiently (i.e., make the study more compact)? So you can see the issue I'm referring to, I've pasted the code for my plot before which should be reproducible if you run it in R.
>
> Any assistance would be greatly appreciated. I think it would be quite difficult for me to make the plot in another package for my publication.
>
> All Best,
> James
>
> ###################################################################################
> # install libraries
> library(psych)
> library(metafor)
> library(meta)
> library(psychometric)
>
> # Entering in data
> x1 <- c("1","2","3","4","5")
> x2 <- c("Race Attitudes","Race Attitudes","Gender Identity", "Gender Identity", "Gender Identity")
> x3 <- c(.342,.253,.631,.559,.563)
> x4 <- c(101,98,98,90,88)
> x5 <- c(1,28,1,27,440)
> meta.dat <- data.frame(cbind(x1,x2,x3,x4,x5))
> meta.dat
>
> # Giving names to variables
> names(meta.dat) <- c("Study","domain", "r","N","time")
>
> # Making sure that variables are either numeric or factors
> meta.dat$r <- as.numeric(as.character(meta.dat$r))
> meta.dat$N <- as.numeric(as.character(meta.dat$N))
> meta.dat$domain <- factor(meta.dat$domain)
> meta.dat$time <- as.numeric(as.character(meta.dat$time))
>
> # Making race the comparison group
> meta.dat <- within(meta.dat, domain <- relevel(domain, ref = "Race Attitudes"))
>
> ####################
> # Setting up correlations for analysis
> ####################
>
> # Convert correlations to z-metric
> meta.dat$fisher.r <- r2z(meta.dat$r)
>
> # Getting the variance weight for each estimate
> meta.dat$var <- (1/(meta.dat$N-3))
>
> # Getting the SE for each estimate
> meta.dat$se <- sqrt(meta.dat$var)
>
> ####################
> # Getting overall results in two packages
> ####################
>
> # r metric
> mod1.z <- metagen(fisher.r,se,data=meta.dat,sm = "ZCOR",backtransf = TRUE)
> mod1.z
>
> x <- rma(yi = meta.dat$fisher.r, vi =meta.dat$var, method = "FE")
> summary(x)
> predict(x, transf=transf.ztor)
>
> # Setting values for plots
> names(meta.dat)
> n <- c("101","98","98","90","88")
> study <- c("1","2","3","4","5")
> cont <- round(weights(x),1)
> cont <- paste(cont,"%",sep = "")
> domain <- c("Race Attitudes","Race Attitudes","Gender Identity", "Gender Identity", "Gender Identity")
> lag <- c("< 1 day", "28 days", "< 1 day", "27 days", "440 days")
>
> # Plotting results
> forest.rma(x,
> slab=study,
> transf=transf.ztor,
> ilab=cbind(domain,n,lag,cont),
> ilab.xpos=c(-.91, -.64, -.43, -.18),
> mlab="Fixed Effects Model for All Samples",
> xlab="Pearson's r",
> showweights=FALSE,
> psize = 1,
> col="royalblue",
> level=95,
> digits=3,
> xlim=c(-1.2,1.2))
>
> ### add column headings to the plot
> text(-1.22, 6.3, "Study", pos=4,font=2)
> text(-1.0, 6.3, "Domain", pos=4,font=2)
> text(-.68, 6.3, "N", pos=4,font=4)
> text(-.54, 6.3, "Lag (days)", pos=4,font=2)
> text(-.30, 6.3, "Contribution", pos=4,font=2)
> text(1.21, 6.3, "Pearson's r [95% CI]", pos=2,font=2)
> text(1.12, -.4, "Summary", pos=2,font=2)
More information about the R-sig-meta-analysis
mailing list