# [R-meta] xlim - half text / many studies: row text problemes

P. Roberto Bakker robertob@kker @ending from gm@il@com
Mon Jun 11 15:17:26 CEST 2018

```Hi Anne-Wil,

Thank you so much for your information.
I will let you know if I have more questions.

All the best (en hartelijke groet ook),

Roberto

2018-06-11 14:36 GMT+02:00 Anne-Wil Kruijt <mail using awkruijt.nl>:

> Hi Robert and list,
>
> The problem is not so much with the internal code of the plot (such that
> changing the size of, for instance, the axes will solve it), but with the
> space that is made available for the plot - it is just not high enough for
> I wrote some script with examples, comments, and the solution that I use
> (printing the plot as a .png with specified dimensions), which I paste
> below. I hope this solves it for you. Please let me know if it doesn't!
>
> All best (hartelijke groet!),
>
> Anne-Wil
>
>
> ###  start of example script
>
> # this is code given as an example of a forest plot in metafor's
> documentation:
>
> ### 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)
>
>
> # now we double up the number of records by creating an 'example data
> frame' (edf) which consists of
> # the same data use above copied twice:
>
> edf <- rbind(dat.bcg, dat.bcg)
> res <- rma(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=edf,
>            slab=paste(author, year, sep=", "))
>
> # now the forest plot shows those overlapping rows that you have for your
> data too:
> forest(res)
>
>
> # the problem is that the number of rows doubles, but the total dimensions
> made available (by rmarkdown) to plot it in are still the same.
>
> # if you're working in a .rmd file, a quick-glance workaround is to hit
> the left one of the three tiny light gray icons that appear at the top
> right of the plot output (right below the chunk you're working in). It will
> open a pop up window that you can resize.
> # if you're working in 'plain r studio', you can hit the icon on the right
> of three icons at the top left of the 'viewer pane' to get a resizable pop
> up window with the plot.
>
> # personally, I use the above for quick glances, and use the code below to
> create the images that I eventually use in papers, presentations etc.
> # It allows you to set the required resolution and size (in pixels), as
> well as the background color (in this example it's set to transparent,
> which can be nice for powerpoints with a coloured background).
>
> # if you're working on a mac you may need to install xquartz if you don't
> have it yet (https://www.xquartz.org/); if you're on windows I don't know
> if you need additional software (but I suspect not - perhaps you won't even
> need the dev.off() line on windows either).
>
> # it is important (on my computer at least) to run the three lines (png(),
> plotcall, dev.off()) in one go (select the three, then run, or place them
> in their own chunk and then run - but don't run them line by line)
>
> # these two sets of three lines (and the DPI setting line) will save the
> same plot (forest(res)) twice, as .pngs in your working directory. You
> won't see the plots appear in R itself (! - it will only show some text
> like "null device 1") but you can find them using finder/explorer.
> # The first set of three lines saves it as a .png with width = 500 and
> height = 350 (giving slighly overlapping lines), the second set saves it as
> a .png with width = 500 and height = 600, which is a lot more pleasant.
> Just toy around with the width and heigth settings untill the plots feels
> good for you purposes.
>
> # enjoy!
>
> dpi = 150
>
>
> png(filename = "foresplot500by350.png", width= (500 *(dpi/72)), height=
> (350 * (dpi/72)), res = dpi, bg = "transparent") # info on the file to save
> forest(res) # the r code for a plot - could also be ggplot, base plot, etc
> dev.off()  # close the connection with the external writer.
>
>
> png(filename = "foresplot500by600.png", width= (500 *(dpi/72)), height=
> (600 * (dpi/72)), res = dpi, bg = "transparent")
> forest(res)
> dev.off()
>
> ### end of example script
>
>
>
> ﻿On 2018-06-11, 13:37, "R-sig-meta-analysis on behalf of P. Roberto
> Bakker" <r-sig-meta-analysis-bounces using r-project.org on behalf of
> robertobakker using gmail.com> wrote:
>
>     Hi,
>
>     My R page is 3.5.0.
>     My question is about forest() in metafor.
>
>
>     Best,
>     Roberto
>
>     2018-06-08 18:21 GMT+02:00 P. Roberto Bakker <robertobakker using gmail.com
> >:
>
>     > Hi,
>     >
>     > My apologies, I forgot telling, the package is metafor/forest
>     >
>     > Best and thank you in advance,
>     >
>     > Roberto
>     >
>     > 2018-06-07 10:11 GMT-04:00 P. Roberto Bakker <
> robertobakker using gmail.com>:
>     >
>     >> Hi,
>     >>
>     >> When I change 'xlim(-1, 49)' into  'xlim(1, 49)'  then the lower
> half of
>     >> text "RE Model..." disappears.
>     >> How can I correct this?
>     >>
>     >> Reason for changing the 'xlim' is because this meta-analysis
> contains a
>     >> lot of studies and therefore  row texts overlap. A smaller font
> makes it
>     >> By lowering the lower xlim the text font is better.
>     >> Is ther a better way?
>     >>
>     >> Best and thank you in advance,
>     >>
>     >> Roberto
>     >>
>     >
>     >
>
>         [[alternative HTML version deleted]]
>
>     _______________________________________________
>     R-sig-meta-analysis mailing list
>     R-sig-meta-analysis using r-project.org
>     https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis
>
>
>
>

[[alternative HTML version deleted]]

```