My script is the following:
library(metafor)
yi<-c(-0.1, 0.2, 0.3, 0.4)
sei<-c(0.4, 0.2, 0.6, 0.1)
vi<-sei^2
studi<-c("A", "B", "C", "D")
eventi.c<-c(10, 5, 7, 6)
n.c<-c(11, 34, 25, 20)
eventi.a<-c(2, 7, 6, 5)
n.a<-c(11, 35, 25, 15)
dfs<-rma(yi, vi, method="DL")
dfs
windows(height=6, width=10, pointsize=10)
windowsFonts(B=windowsFont("Bookman Old Style"))
forest.rma(dfs, slab=studi, xlim=c(-15, 10), ilab=cbind(eventi.c, n.c,
eventi.a, n.a), ilab.xpos=c(-9.5, -8, -6, -4.5), cex=1.2, at=c(-2, -1, 0, 1,
2), family="B", xlab="Hazard Ratio (log scale)", mlab="Random Effects
Model", efac=5, col="red", border="red")
text(-10, -1.3, paste("Heterogeneity: I-squared=", paste(paste(round(dfs$I2,
2), "%", sep=""), paste("p", round(dfs$QEp, 4), sep="="), sep=", "),
sep=""), font=4, cex=1.2, family="B")
op<-par(cex=1.2, font=2, family="B", oma=c(0.5, 0.5, 0.5, 0.5), mar=c(0.5,
0.5, 0.5, 0.5))
text(x=c(-9.5, -8, -6, -4.5), 6, c("Events", "N", "Events", "N"), cex=1.2 )
text(c(-8.7, -5.5, 8), 6.5, c("S", "A", "Log"))
text(-15, 6, "Trials", pos=4)
text(10, 6, "Hazard Ratio [95% CI]", pos=2)
par(op)
Even if I have specified "col="red", border="red"", color of squares and
diamond rests black! Why?
Thanks,
Paola
--
View this message in context: http://r.789695.n4.nabble.com/Change-color-in-forest-rma-metafor-tp3765090p3765090.html
Sent from the R help mailing list archive at Nabble.com.
Change color in forest.rma (metafor)
11 messages · Bernd Weiss, Uwe Ligges, Paola Tellaroli +1 more
Am 24.08.2011 07:50, schrieb Paola Tellaroli:
My script is the following:
library(metafor)
yi<-c(-0.1, 0.2, 0.3, 0.4)
sei<-c(0.4, 0.2, 0.6, 0.1)
vi<-sei^2
studi<-c("A", "B", "C", "D")
eventi.c<-c(10, 5, 7, 6)
n.c<-c(11, 34, 25, 20)
eventi.a<-c(2, 7, 6, 5)
n.a<-c(11, 35, 25, 15)
dfs<-rma(yi, vi, method="DL")
dfs
windows(height=6, width=10, pointsize=10)
windowsFonts(B=windowsFont("Bookman Old Style"))
forest.rma(dfs, slab=studi, xlim=c(-15, 10), ilab=cbind(eventi.c, n.c,
eventi.a, n.a), ilab.xpos=c(-9.5, -8, -6, -4.5), cex=1.2, at=c(-2, -1, 0, 1,
2), family="B", xlab="Hazard Ratio (log scale)", mlab="Random Effects
Model", efac=5, col="red", border="red")
text(-10, -1.3, paste("Heterogeneity: I-squared=", paste(paste(round(dfs$I2,
2), "%", sep=""), paste("p", round(dfs$QEp, 4), sep="="), sep=", "),
sep=""), font=4, cex=1.2, family="B")
op<-par(cex=1.2, font=2, family="B", oma=c(0.5, 0.5, 0.5, 0.5), mar=c(0.5,
0.5, 0.5, 0.5))
text(x=c(-9.5, -8, -6, -4.5), 6, c("Events", "N", "Events", "N"), cex=1.2 )
text(c(-8.7, -5.5, 8), 6.5, c("S", "A", "Log"))
text(-15, 6, "Trials", pos=4)
text(10, 6, "Hazard Ratio [95% CI]", pos=2)
par(op)
Even if I have specified "col="red", border="red"", color of squares and
diamond rests black! Why?
As far as I know, "col" and "border" do only affect the fitted values
("diamonds"), i.e. the FEM/REM estimators (see ?forest.rma: "col:
character string specifying the name of a color to use for _the fitted_
values (?"darkgray"? by default).")
Furthermore, I had a quick look at the source code and it might be a
bug. If I replace in line 2770 the line
cex * efac), col = "black", ...)
with
cex * efac), col = col, ...)
you can at least specify your own colour. Changing the border color
seems a bit more tricky...
However, Wolfgang Viechbauer (the package author) is always a very
responsive and helpful person and I suggest you better wait for his answer.
Bernd
Thank you, Bernd, for looking into this. Yes, at the moment, the color of the summary estimate for models without moderators is hard-coded (as black). I didn't think people may want to change that. I guess I was wrong =) A dirty solution for the moment is to add: addpoly(dfs, efac=6, row=-1, col="red", border="red", annotate=F, mlab="") after the call to forest(). You will get a warning message (since the border argument gets passed to the text() function inside addpoly() and that's not a par for text), but you can just ignore that. Best,
Wolfgang Viechtbauer Department of Psychiatry and Neuropsychology School for Mental Health and Neuroscience Maastricht University, P.O. Box 616 6200 MD Maastricht, The Netherlands Tel: +31 (43) 368-5248 Fax: +31 (43) 368-8689 Web: http://www.wvbauer.com > -----Original Message----- > From: Bernd Weiss [mailto:bernd.weiss at uni-koeln.de] > Sent: Wednesday, August 24, 2011 16:22 > To: Paola Tellaroli > Cc: wvb at metafor-project.org; r-help at r-project.org > Subject: Re: [R] Change color in forest.rma (metafor) > > Am 24.08.2011 07:50, schrieb Paola Tellaroli: > > My script is the following: > > > > library(metafor) > > > > yi<-c(-0.1, 0.2, 0.3, 0.4) > > sei<-c(0.4, 0.2, 0.6, 0.1) > > vi<-sei^2 > > studi<-c("A", "B", "C", "D") > > eventi.c<-c(10, 5, 7, 6) > > n.c<-c(11, 34, 25, 20) > > eventi.a<-c(2, 7, 6, 5) > > n.a<-c(11, 35, 25, 15) > > dfs<-rma(yi, vi, method="DL") > > dfs > > > > windows(height=6, width=10, pointsize=10) > > windowsFonts(B=windowsFont("Bookman Old Style")) > > > > forest.rma(dfs, slab=studi, xlim=c(-15, 10), ilab=cbind(eventi.c, n.c, > > eventi.a, n.a), ilab.xpos=c(-9.5, -8, -6, -4.5), cex=1.2, at=c(-2, -1, > 0, 1, > > 2), family="B", xlab="Hazard Ratio (log scale)", mlab="Random Effects > > Model", efac=5, col="red", border="red") > > text(-10, -1.3, paste("Heterogeneity: I-squared=", > paste(paste(round(dfs$I2, > > 2), "%", sep=""), paste("p", round(dfs$QEp, 4), sep="="), sep=", "), > > sep=""), font=4, cex=1.2, family="B") > > > > op<-par(cex=1.2, font=2, family="B", oma=c(0.5, 0.5, 0.5, 0.5), > mar=c(0.5, > > 0.5, 0.5, 0.5)) > > text(x=c(-9.5, -8, -6, -4.5), 6, c("Events", "N", "Events", "N"), > cex=1.2 ) > > text(c(-8.7, -5.5, 8), 6.5, c("S", "A", "Log")) > > text(-15, 6, "Trials", pos=4) > > text(10, 6, "Hazard Ratio [95% CI]", pos=2) > > par(op) > > > > Even if I have specified "col="red", border="red"", color of squares and > > diamond rests black! Why? > > As far as I know, "col" and "border" do only affect the fitted values > ("diamonds"), i.e. the FEM/REM estimators (see ?forest.rma: "col: > character string specifying the name of a color to use for _the fitted_ > values ('"darkgray"' by default).") > > Furthermore, I had a quick look at the source code and it might be a > bug. If I replace in line 2770 the line > > cex * efac), col = "black", ...) > > with > > cex * efac), col = col, ...) > > you can at least specify your own colour. Changing the border color > seems a bit more tricky... > > However, Wolfgang Viechbauer (the package author) is always a very > responsive and helpful person and I suggest you better wait for his > answer. > > Bernd
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110825/830ff401/attachment.pl>
The color of the squares is also currently hard coded. The thing is, there are so many different elements to a forest plot (squares, lines, polygons, text, axes, axis labels, etc.), if I would add arguments to set the color of each element, things would really get out of hand (as far as I am concerned, there are already too many arguments to begin with). I can think of one possibility: I could allow the col argument to accept a vector of colors and then apply the different elements of that vector to the various elements in the plot. Of course, there is also a limit to how far that can be taken. For example, what if somebody wants to have a different color for *one* of the squares and a different color for the other squares? Another possibility is to do some post-processing with other software. One can create the forest plot in R, save it for example as a postscript file, and the edit the plot in other software. Yes, I prefer it if I can create the plot in R and have it exactly the way I want it (without having to do any post-processing), but sometimes that may not be possible. Note that you can always add whatever you want to a plot created by the forest() function after it has been drawn. You can add text, lines, squares, polygons, whatever in any color you desire (e.g., with the text(), segments(), points(), polygon() functions). So, you could also just plot over the squares with: points(yi, 4:1, pch=15, col="red") To get rid of the black squares that are drawn by the forest function, add psize=0 as an argument in forest() (this will make the size of squares equal to 0, so essentially, they are invisible). If you want to make the size of the points inversely proportional to some function of the precision of the estimates, use points() together with the cex argument. For example: wi <- 1/sqrt(vi) psize <- wi/sum(wi) psize <- (psize - min(psize)) / (max(psize) - min(psize)) psize <- (psize * 1.0) + 0.5 points(yi, 4:1, pch=15, col="red", cex=psize) Best, Wolfgang
-----Original Message----- From: Paola Tellaroli [mailto:paola.tellaroli at gmail.com] Sent: Thursday, August 25, 2011 10:57 To: Viechtbauer Wolfgang (STAT) Cc: r-help at r-project.org; Bernd Weiss Subject: Re: [R] Change color in forest.rma (metafor) Thank you for your attention and help! In this way I get the diamond coloured, but actually I would have the squares representing the values of the individual studies coloured. Is it somehow possible? Paola 2011/8/24 Viechtbauer Wolfgang (STAT) <wolfgang.viechtbauer at maastrichtuniversity.nl> Thank you, Bernd, for looking into this. Yes, at the moment, the color of the summary estimate for models without moderators is hard-coded (as black). I didn't think people may want to change that. I guess I was wrong =) A dirty solution for the moment is to add: addpoly(dfs, efac=6, row=-1, col="red", border="red", annotate=F, mlab="") after the call to forest(). You will get a warning message (since the border argument gets passed to the text() function inside addpoly() and that's not a par for text), but you can just ignore that. Best, -- Wolfgang Viechtbauer Department of Psychiatry and Neuropsychology School for Mental Health and Neuroscience Maastricht University, P.O. Box 616 6200 MD Maastricht, The Netherlands Tel: +31 (43) 368-5248 Fax: +31 (43) 368-8689 Web: http://www.wvbauer.com
-----Original Message----- From: Bernd Weiss [mailto:bernd.weiss at uni-koeln.de] Sent: Wednesday, August 24, 2011 16:22 To: Paola Tellaroli Cc: wvb at metafor-project.org; r-help at r-project.org Subject: Re: [R] Change color in forest.rma (metafor) Am 24.08.2011 07:50, schrieb Paola Tellaroli:
My script is the following:
library(metafor)
yi<-c(-0.1, 0.2, 0.3, 0.4)
sei<-c(0.4, 0.2, 0.6, 0.1)
vi<-sei^2
studi<-c("A", "B", "C", "D")
eventi.c<-c(10, 5, 7, 6)
n.c<-c(11, 34, 25, 20)
eventi.a<-c(2, 7, 6, 5)
n.a<-c(11, 35, 25, 15)
dfs<-rma(yi, vi, method="DL")
dfs
windows(height=6, width=10, pointsize=10)
windowsFonts(B=windowsFont("Bookman Old Style"))
forest.rma(dfs, slab=studi, xlim=c(-15, 10), ilab=cbind(eventi.c, n.c,
eventi.a, n.a), ilab.xpos=c(-9.5, -8, -6, -4.5), cex=1.2, at=c(-2, -1,
0, 1,
2), family="B", xlab="Hazard Ratio (log scale)", mlab="Random Effects
Model", efac=5, col="red", border="red")
text(-10, -1.3, paste("Heterogeneity: I-squared=",
paste(paste(round(dfs$I2,
2), "%", sep=""), paste("p", round(dfs$QEp, 4), sep="="), sep=", "),
sep=""), font=4, cex=1.2, family="B")
op<-par(cex=1.2, font=2, family="B", oma=c(0.5, 0.5, 0.5, 0.5),
mar=c(0.5,
0.5, 0.5, 0.5))
text(x=c(-9.5, -8, -6, -4.5), 6, c("Events", "N", "Events", "N"),
cex=1.2 )
text(c(-8.7, -5.5, 8), 6.5, c("S", "A", "Log"))
text(-15, 6, "Trials", pos=4)
text(10, 6, "Hazard Ratio [95% CI]", pos=2)
par(op)
Even if I have specified "col="red", border="red"", color of squares
and
diamond rests black! Why?
As far as I know, "col" and "border" do only affect the fitted values
("diamonds"), i.e. the FEM/REM estimators (see ?forest.rma: "col:
character string specifying the name of a color to use for _the fitted_
values ('"darkgray"' by default).")
Furthermore, I had a quick look at the source code and it might be a
bug. If I replace in line 2770 the line
cex * efac), col = "black", ...)
with
cex * efac), col = col, ...)
you can at least specify your own colour. Changing the border color
seems a bit more tricky...
However, Wolfgang Viechbauer (the package author) is always a very
responsive and helpful person and I suggest you better wait for his
answer.
Bernd
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110826/492cc36c/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110826/e23c9fff/attachment.pl>
2 days later
On 26.08.2011 15:50, Paola Tellaroli wrote:
I lied, that was not my last question: how can I add two arrows at the bottom with the words "in favor of A / B"? This is not specified in the pdf and with "text" I have the impression that I can't add text below the x-axis.
You can, see ?par and its "xpd" argument. Uwe Ligges
2011/8/26 Paola Tellaroli<paola.tellaroli at gmail.com>
Dear Prof. Viechtbauer, thank you so much for your help and kindness. Clearly graphs are the minor problem in our work, and the parameters and options that can vary in R are so many that it is obvious that you can not expect to change everything you want! Your suggestions are very helpuf, but I have one last question. I'm trying to copy the style of a forest plot that I've seen and I like (the one in the attached file, page 1034): can I do this in R? Best wishes, *Paola* 2011/8/25 Viechtbauer Wolfgang (STAT)-2 [via R]< ml-node+3768683-1225159815-262246 at n4.nabble.com>
The color of the squares is also currently hard coded. The thing is, there are so many different elements to a forest plot (squares, lines, polygons, text, axes, axis labels, etc.), if I would add arguments to set the color of each element, things would really get out of hand (as far as I am concerned, there are already too many arguments to begin with). I can think of one possibility: I could allow the col argument to accept a vector of colors and then apply the different elements of that vector to the various elements in the plot. Of course, there is also a limit to how far that can be taken. For example, what if somebody wants to have a different color for *one* of the squares and a different color for the other squares? Another possibility is to do some post-processing with other software. One can create the forest plot in R, save it for example as a postscript file, and the edit the plot in other software. Yes, I prefer it if I can create the plot in R and have it exactly the way I want it (without having to do any post-processing), but sometimes that may not be possible. Note that you can always add whatever you want to a plot created by the forest() function after it has been drawn. You can add text, lines, squares, polygons, whatever in any color you desire (e.g., with the text(), segments(), points(), polygon() functions). So, you could also just plot over the squares with: points(yi, 4:1, pch=15, col="red") To get rid of the black squares that are drawn by the forest function, add psize=0 as an argument in forest() (this will make the size of squares equal to 0, so essentially, they are invisible). If you want to make the size of the points inversely proportional to some function of the precision of the estimates, use points() together with the cex argument. For example: wi<- 1/sqrt(vi) psize<- wi/sum(wi) psize<- (psize - min(psize)) / (max(psize) - min(psize)) psize<- (psize * 1.0) + 0.5 points(yi, 4:1, pch=15, col="red", cex=psize) Best, Wolfgang
-----Original Message----- From: Paola Tellaroli [mailto:[hidden email]<http://user/SendEmail.jtp?type=node&node=3768683&i=0>]
Sent: Thursday, August 25, 2011 10:57 To: Viechtbauer Wolfgang (STAT) Cc: [hidden email]<http://user/SendEmail.jtp?type=node&node=3768683&i=1>;
Bernd Weiss
Subject: Re: [R] Change color in forest.rma (metafor) Thank you for your attention and help! In this way I get the diamond coloured, but actually I would have the squares representing the values of the individual studies coloured. Is
it
somehow possible? Paola 2011/8/24 Viechtbauer Wolfgang (STAT) <[hidden email]<http://user/SendEmail.jtp?type=node&node=3768683&i=2>>
Thank you, Bernd, for looking into this. Yes, at the moment, the color of the summary estimate for models without
moderators is hard-coded (as black). I didn't think people may want to change that. I guess I was wrong =) A dirty solution for the moment is to add: addpoly(dfs, efac=6, row=-1, col="red", border="red", annotate=F,
mlab="")
after the call to forest(). You will get a warning message (since the border argument gets passed to the text() function inside addpoly() and that's not a par for text), but you can just ignore that. Best, -- Wolfgang Viechtbauer Department of Psychiatry and Neuropsychology School for Mental Health and Neuroscience Maastricht University, P.O. Box 616 6200 MD Maastricht, The Netherlands Tel: +31 (43) 368-5248 Fax: +31 (43) 368-8689 Web: http://www.wvbauer.com
-----Original Message----- From: Bernd Weiss [mailto:[hidden email]<http://user/SendEmail.jtp?type=node&node=3768683&i=3>]
Sent: Wednesday, August 24, 2011 16:22 To: Paola Tellaroli Cc: [hidden email]<http://user/SendEmail.jtp?type=node&node=3768683&i=4>;
[hidden email]<http://user/SendEmail.jtp?type=node&node=3768683&i=5>
Subject: Re: [R] Change color in forest.rma (metafor) Am 24.08.2011 07:50, schrieb Paola Tellaroli:
My script is the following:
library(metafor)
yi<-c(-0.1, 0.2, 0.3, 0.4)
sei<-c(0.4, 0.2, 0.6, 0.1)
vi<-sei^2
studi<-c("A", "B", "C", "D")
eventi.c<-c(10, 5, 7, 6)
n.c<-c(11, 34, 25, 20)
eventi.a<-c(2, 7, 6, 5)
n.a<-c(11, 35, 25, 15)
dfs<-rma(yi, vi, method="DL")
dfs
windows(height=6, width=10, pointsize=10)
windowsFonts(B=windowsFont("Bookman Old Style"))
forest.rma(dfs, slab=studi, xlim=c(-15, 10), ilab=cbind(eventi.c,
n.c,
eventi.a, n.a), ilab.xpos=c(-9.5, -8, -6, -4.5), cex=1.2, at=c(-2,
-1,
0, 1,
2), family="B", xlab="Hazard Ratio (log scale)", mlab="Random
Effects
Model", efac=5, col="red", border="red")
text(-10, -1.3, paste("Heterogeneity: I-squared=",
paste(paste(round(dfs$I2,
2), "%", sep=""), paste("p", round(dfs$QEp, 4), sep="="), sep=", "),
sep=""), font=4, cex=1.2, family="B") op<-par(cex=1.2, font=2, family="B", oma=c(0.5, 0.5, 0.5, 0.5),
mar=c(0.5,
0.5, 0.5, 0.5))
text(x=c(-9.5, -8, -6, -4.5), 6, c("Events", "N", "Events", "N"),
cex=1.2 )
text(c(-8.7, -5.5, 8), 6.5, c("S", "A", "Log"))
text(-15, 6, "Trials", pos=4)
text(10, 6, "Hazard Ratio [95% CI]", pos=2)
par(op)
Even if I have specified "col="red", border="red"", color of squares
and
diamond rests black! Why?
As far as I know, "col" and "border" do only affect the fitted values
("diamonds"), i.e. the FEM/REM estimators (see ?forest.rma: "col:
character string specifying the name of a color to use for _the
fitted_
values ('"darkgray"' by default).")
Furthermore, I had a quick look at the source code and it might be a
bug. If I replace in line 2770 the line
cex * efac), col = "black", ...)
with
cex * efac), col = col, ...)
you can at least specify your own colour. Changing the border color
seems a bit more tricky...
However, Wolfgang Viechbauer (the package author) is always a very
responsive and helpful person and I suggest you better wait for his
answer.
Bernd
______________________________________________ [hidden email]<http://user/SendEmail.jtp?type=node&node=3768683&i=6>mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ------------------------------ If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/Change-color-in-forest-rma-metafor-tp3765090p3768683.html To unsubscribe from Change color in forest.rma (metafor), click here<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3765090&code=cGFvbGEudGVsbGFyb2xpQGdtYWlsLmNvbXwzNzY1MDkwfDQzMzczMjk1Ng==>.
-- View this message in context: http://r.789695.n4.nabble.com/Change-color-in-forest-rma-metafor-tp3765090p3770899.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110829/3dfdb24e/attachment.pl>
See ?par and its "mar" argument.
Could you tell me also how to change the size of the chart? There is not enough space below the chart to add the arrows!
On 29.08.2011 13:11, Paola Tellaroli wrote:
Thank you so much!!! Could you tell me also how to change the size of the chart? There is not enough space below the chart to add the arrows!
Please read the whole help page for ?par You will find a way how to increase the size of the margins (using the argument "mar") and many other useful things. Uwe Ligges
2011/8/28 Uwe Ligges-3 [via R]< ml-node+3774557-1567708350-262246 at n4.nabble.com>
On 26.08.2011 15:50, Paola Tellaroli wrote:
I lied, that was not my last question: how can I add two arrows at the bottom with the words "in favor of A / B"? This is not specified in the
and with "text" I have the impression that I can't add text below the x-axis.
You can, see ?par and its "xpd" argument. Uwe Ligges
2011/8/26 Paola Tellaroli<[hidden email]<http://user/SendEmail.jtp?type=node&node=3774557&i=0>>
Dear Prof. Viechtbauer, thank you so much for your help and kindness. Clearly graphs are the minor problem in our work, and the parameters and
options that can vary in R are so many that it is obvious that you can
not expect
to change everything you want! Your suggestions are very helpuf, but I have one last question. I'm
trying
to copy the style of a forest plot that I've seen and I like (the one in
the
attached file, page 1034): can I do this in R? Best wishes, *Paola* 2011/8/25 Viechtbauer Wolfgang (STAT)-2 [via R]< [hidden email]<http://user/SendEmail.jtp?type=node&node=3774557&i=1>>
The color of the squares is also currently hard coded. The thing is, there are so many different elements to a forest plot (squares, lines, polygons, text, axes, axis labels, etc.), if I would
add
arguments to set the color of each element, things would really get out
of
hand (as far as I am concerned, there are already too many arguments to
begin with). I can think of one possibility: I could allow the col
argument
to accept a vector of colors and then apply the different elements of
that
vector to the various elements in the plot. Of course, there is also a
limit
to how far that can be taken. For example, what if somebody wants to
have a
different color for *one* of the squares and a different color for the
other
squares? Another possibility is to do some post-processing with other software.
One
can create the forest plot in R, save it for example as a postscript
file,
and the edit the plot in other software. Yes, I prefer it if I can
create
the plot in R and have it exactly the way I want it (without having to
do
any post-processing), but sometimes that may not be possible. Note that you can always add whatever you want to a plot created by the
forest() function after it has been drawn. You can add text, lines,
squares,
polygons, whatever in any color you desire (e.g., with the text(), segments(), points(), polygon() functions). So, you could also just
plot
over the squares with: points(yi, 4:1, pch=15, col="red") To get rid of the black squares that are drawn by the forest function,
add
psize=0 as an argument in forest() (this will make the size of squares
equal
to 0, so essentially, they are invisible). If you want to make the size of the points inversely proportional to
some
function of the precision of the estimates, use points() together with
the
cex argument. For example: wi<- 1/sqrt(vi) psize<- wi/sum(wi) psize<- (psize - min(psize)) / (max(psize) - min(psize)) psize<- (psize * 1.0) + 0.5 points(yi, 4:1, pch=15, col="red", cex=psize) Best, Wolfgang
-----Original Message----- From: Paola Tellaroli [mailto:[hidden email]<
http://user/SendEmail.jtp?type=node&node=3768683&i=0>]
Sent: Thursday, August 25, 2011 10:57 To: Viechtbauer Wolfgang (STAT) Cc: [hidden email]<
http://user/SendEmail.jtp?type=node&node=3768683&i=1>;
Bernd Weiss
Subject: Re: [R] Change color in forest.rma (metafor) Thank you for your attention and help! In this way I get the diamond coloured, but actually I would have the squares representing the values of the individual studies coloured. Is
it
somehow possible? Paola 2011/8/24 Viechtbauer Wolfgang (STAT) <[hidden email]<http://user/SendEmail.jtp?type=node&node=3768683&i=2>>
Thank you, Bernd, for looking into this. Yes, at the moment, the color of the summary estimate for models
without
moderators is hard-coded (as black). I didn't think people may want to
change that. I guess I was wrong =) A dirty solution for the moment is to add: addpoly(dfs, efac=6, row=-1, col="red", border="red", annotate=F,
mlab="")
after the call to forest(). You will get a warning message (since the border argument gets passed to the text() function inside addpoly()
and
that's not a par for text), but you can just ignore that. Best, -- Wolfgang Viechtbauer Department of Psychiatry and Neuropsychology School for Mental Health and Neuroscience Maastricht University, P.O. Box 616 6200 MD Maastricht, The Netherlands Tel: +31 (43) 368-5248 Fax: +31 (43) 368-8689 Web: http://www.wvbauer.com
-----Original Message----- From: Bernd Weiss [mailto:[hidden email]<
http://user/SendEmail.jtp?type=node&node=3768683&i=3>]
Sent: Wednesday, August 24, 2011 16:22 To: Paola Tellaroli Cc: [hidden email]<
http://user/SendEmail.jtp?type=node&node=3768683&i=4>;
[hidden email]<http://user/SendEmail.jtp?type=node&node=3768683&i=5>
Subject: Re: [R] Change color in forest.rma (metafor) Am 24.08.2011 07:50, schrieb Paola Tellaroli:
My script is the following:
library(metafor)
yi<-c(-0.1, 0.2, 0.3, 0.4)
sei<-c(0.4, 0.2, 0.6, 0.1)
vi<-sei^2
studi<-c("A", "B", "C", "D")
eventi.c<-c(10, 5, 7, 6)
n.c<-c(11, 34, 25, 20)
eventi.a<-c(2, 7, 6, 5)
n.a<-c(11, 35, 25, 15)
dfs<-rma(yi, vi, method="DL")
dfs
windows(height=6, width=10, pointsize=10)
windowsFonts(B=windowsFont("Bookman Old Style"))
forest.rma(dfs, slab=studi, xlim=c(-15, 10), ilab=cbind(eventi.c,
n.c,
eventi.a, n.a), ilab.xpos=c(-9.5, -8, -6, -4.5), cex=1.2, at=c(-2,
-1,
0, 1,
2), family="B", xlab="Hazard Ratio (log scale)", mlab="Random
Effects
Model", efac=5, col="red", border="red")
text(-10, -1.3, paste("Heterogeneity: I-squared=",
paste(paste(round(dfs$I2,
2), "%", sep=""), paste("p", round(dfs$QEp, 4), sep="="), sep=", "),
sep=""), font=4, cex=1.2, family="B") op<-par(cex=1.2, font=2, family="B", oma=c(0.5, 0.5, 0.5, 0.5),
mar=c(0.5,
0.5, 0.5, 0.5))
text(x=c(-9.5, -8, -6, -4.5), 6, c("Events", "N", "Events", "N"),
cex=1.2 )
text(c(-8.7, -5.5, 8), 6.5, c("S", "A", "Log"))
text(-15, 6, "Trials", pos=4)
text(10, 6, "Hazard Ratio [95% CI]", pos=2)
par(op)
Even if I have specified "col="red", border="red"", color of squares
and
diamond rests black! Why?
As far as I know, "col" and "border" do only affect the fitted values
("diamonds"), i.e. the FEM/REM estimators (see ?forest.rma: "col:
character string specifying the name of a color to use for _the
fitted_
values ('"darkgray"' by default).")
Furthermore, I had a quick look at the source code and it might be a
bug. If I replace in line 2770 the line
cex * efac), col = "black", ...)
with
cex * efac), col = col, ...)
you can at least specify your own colour. Changing the border color
seems a bit more tricky...
However, Wolfgang Viechbauer (the package author) is always a very
responsive and helpful person and I suggest you better wait for his
answer.
Bernd
______________________________________________ [hidden email]<http://user/SendEmail.jtp?type=node&node=3768683&i=6>mailing
list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ------------------------------ If you reply to this email, your message will be added to the
discussion
below:
-- View this message in context:
Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
______________________________________________ [hidden email]<http://user/SendEmail.jtp?type=node&node=3774557&i=2>mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email]<http://user/SendEmail.jtp?type=node&node=3774557&i=3>mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ------------------------------ If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/Change-color-in-forest-rma-metafor-tp3765090p3774557.html To unsubscribe from Change color in forest.rma (metafor), click here<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3765090&code=cGFvbGEudGVsbGFyb2xpQGdtYWlsLmNvbXwzNzY1MDkwfDQzMzczMjk1Ng==>.
-- View this message in context: http://r.789695.n4.nabble.com/Change-color-in-forest-rma-metafor-tp3765090p3775946.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.