[R-meta] metafor forest 'ylim()': 1.row distances change, 2 .relative lines?
P. Roberto Bakker
robertob@kker @ending from gm@il@com
Wed Sep 26 11:08:18 CEST 2018
Hi Wolfgang,
Thank you for you information.
I did the following but I receive the message "Error in plot.new() : figure
margins too large"
What should I do? Thank you in advance, Roberto
datsub <- subset(dat, type == "MAOI")
res.res <- rma(measure="SMCC", yi=yi, vi=vi, data=datsub, digits=2, method
= "REML")
##
res <- 200 # pixels per inch - Roberto: I did not know which number so I
chose 200
fact <- par("mai")[1]/par("mar")[1] # calculate inches per line
### this following part is copied from inside the forest()-function.
# forest() modifies the margin internally in the same way.
par.mar <- par("mar")
par.mar.adj <- par.mar - c(0, 3, 1, 1) #Roberto: I changed the number of
the vector 'c()' but the abovementioned message keeps coming back
par.mar.adj[par.mar.adj < 0] <- 0
###
ylim <- c(-1.5, length(datsub$yi)+3) #In the webpage I could not find
'ma$' as mentioned in syntax; I suppose it should be the database
ylim.abs <- abs(ylim[1])+abs(ylim[2])-length(datsub$yi) # calculate
absolute distance of ylim-argument
pixel.bottom <- (par.mar.adj[1])*fact*res # calculate pixels to add to
bottom and top based on the margin that is internally used by forest().
pixel.top <- (par.mar.adj[3])*fact*res
png(filename="C:/docs/Work2/Statistic_Analyses/MetaQTcAD/datsub",
width=8,
height=((length(datsub$yi)+ylim.abs)*fact*res) + pixel.bottom +
pixel.top,
res=res)
par(mar=par.mar) # make sure that inside the new device the margins you
want to define are actually used.
forest(res.res, slab = paste(datsub$npd, datsub$tn, sep = ", "), xlab = "",
cex =0.45, cex.lab=0.8, cex.main=0.8, main="MAOI vs placebo - REML -
R=0.5", showweights = T, addfit= T, order=order(datsub$name),
ylim=c(-1,23))
Op ma 24 sep. 2018 om 10:53 schreef Viechtbauer, Wolfgang (SP) <
wolfgang.viechtbauer using maastrichtuniversity.nl>:
> Of course the distances change in absolute terms. The dimensions of the
> plotting device are the same, so how else would one fit k=4 vs k=7 studies
> into the same space without the points falling closer to each other? If you
> want to keep the same distances, then you have to make the size of the
> plotting device smaller/larger.
>
> See also:
> https://stackoverflow.com/questions/25565817/align-text-to-a-plot-with-variable-size-in-r
>
> Best,
> Wolfgang
>
> -----Original Message-----
> From: P. Roberto Bakker [mailto:robertobakker using gmail.com]
> Sent: Monday, 24 September, 2018 8:51
> To: Viechtbauer, Wolfgang (SP)
> Cc: r-sig-meta-analysis using r-project.org
> Subject: Re: [R-meta] metafor forest 'ylim()': 1.row distances change, 2
> .relative lines?
>
> Hi Wolfgang,
>
> My apologies, I did something wrong with registering. Now it should be
> okay.
>
> Thank you for your explaination. Very clear.
>
> Still the study row distances change when the number of studies change
> (see A next to B here below).
> The journal asks for same distances.
> As my meta-analyses are for different medication groups (each with
> different number of studies) the study row distances vary between
> meta-analyses.
> So, what could I do?
> Thank you in advance,
> Roberto
> ###########A###############
> yi <- c(.1, .3, .2, .5)
> vi <- rep(.01, 4)
> res <- rma(yi, vi)
> forest(res)
>
> ### default for ylim is -1.5 to k+3
> ### summary polygon in y=-1
> ### line in y=0
> ### studies in y=1 to k
> ### line in y=k+1
> forest(res, ylim=c(-1.5,res$k+3))
> text(0, -1:7, -1:7)
>
> ############B###############
> yi <- c(.1, .3, .2, .5, .6, .5, .4)
> vi <- rep(.01, 7)
> res <- rma(yi, vi)
> forest(res)
>
> ### default for ylim is -1.5 to k+3
> ### summary polygon in y=-1
> ### line in y=0
> ### studies in y=1 to k
> ### line in y=k+1
> forest(res, ylim=c(-1.5,4))
> text(0, -1:7, -1:20)
> ###########################
>
> Op zo 23 sep. 2018 om 19:28 schreef Viechtbauer, Wolfgang (SP) <
> wolfgang.viechtbauer using maastrichtuniversity.nl>:
> Maybe this helps -- go through this line by line.
>
> yi <- c(.1, .3, .2, .5)
> vi <- rep(.01, 4)
> res <- rma(yi, vi)
> forest(res)
>
> ### default for ylim is -1.5 to k+3
> ### summary polygon in y=-1
> ### line in y=0
> ### studies in y=1 to k
> ### line in y=k+1
> forest(res, ylim=c(-1.5,res$k+3))
> text(0, -1:7, -1:7)
>
> ### change ylim
> forest(res, ylim=c(-3,10))
> text(0, -3:10, -3:10)
>
> ### this creates more space which we indicate subgroups and/or to add
> extra summary polygons
> forest(res, ylim=c(-3,10), row=c(6,5,2,1))
> text(0, -3:10, -3:10)
> text(par()$usr[1], 7, "Group A", font=2, pos=4)
> text(par()$usr[1], 3, "Group B", font=2, pos=4)
> addpoly(rma(yi, vi, subset=1:2), row=-2, mlab="Group A")
> addpoly(rma(yi, vi, subset=3:4), row=-3, mlab="Group A")
>
> Best,
> Wolfgang
>
> -----Original Message-----
> From: R-sig-meta-analysis [mailto:
> r-sig-meta-analysis-bounces using r-project.org] On Behalf Of P. Roberto Bakker
> Sent: Sunday, 23 September, 2018 12:01
> To: r-sig-meta-analysis using r-project.org
> Subject: [R-meta] metafor forest 'ylim()': 1.row distances change, 2
> .relative lines?
>
> Hi
>
> When I change 'ylim()', two things happen that I do not understand:
>
> 1) The study row distances change:
> - e.g. When I change from 'ylim=c(-1, 23)' into 'ylim=c(-1, 10)', then
> 'y=c(-1, 5)', etc
> -> the study row distances increase at every step
> This whould not be a problem if I had only one forest plot - but I have
> several forest plots - so between forestplots the study row distances are
> different.
> 'rows=c()' could be a solution, however, the study row distances between
> forestplots still may differ.
>
> 2. The position of both horizontal lines change when I change one.
> e.g. at every step shown aboven the lower line changes position - the
> summary polygon may even disappear
>
> All in all, I seems to me that 'ylim()' zooms in/out at every change.
>
> In short: when I change one thing 'all other things change'.
>
> I hope I am clear.
>
> Syntax:
> forest(res, slab = paste(datsub$npd, datsub$tn, sep = ", "),
> cex =0.45, cex.lab=0.8, cex.main=0.8, main="MAOI vs placebo - REML
> - R=0.5",
> showweights = TRUE, order=order(datsub$name),
> ylim=c(-1,23))
>
> On my laptop: surface pro 4 64b
> R version 3.5.0 (2018-04-23) -- "Joy in Playing"
> Copyright (C) 2018 The R Foundation for Statistical Computing
> Platform: x86_64-w64-mingw32/x64 (64-bit)
>
[[alternative HTML version deleted]]
More information about the R-sig-meta-analysis
mailing list