[R-meta] Fwd: meta-regression scatterplot in ggplot2: code

Moritz Tobiasch moritztobi@@ch @ending from gm@il@com
Thu May 24 23:15:09 CEST 2018


Dear community,

Wolfgang and Emerson pointed out the code I sent was not working. Please accept my apologies and find the corrected code as txt file, including some plot examples, in the appendix. metascatter-538 uses theme_fivethirtyeight(), -bw uses theme_bw(), the other two use theme_classic() with either geom_linerange() or geom_errorbar().

I’m happy to take any questions.

Best
Moritz


> 
> 
> 
> 
> 
> 
> 
>> Am 24.05.2018 um 21:54 schrieb Emerson M. Del Ponte <delponte using ufv.br <mailto:delponte using ufv.br>>:
>> 
>> No problem! but I am curious to see the plot, can you send a link?
>> 
>> 
>> 
>> Emerson Medeiros Del Ponte
>> Associate Professor & Graduate Studies Chair
>> Departamento de Fitopatologia, Universidade Federal de Viçosa
>> Viçosa MG Brasil  +55 (31) 3899-1103
>> -------------------------------------------------------------
>> Editor in Chief for Tropical Plant Pathology
>> www.sbfitopatologia.org/tpp <http://www.sbfitopatologia.org/tpp>
>> @TropPlantPathol
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> Em qui, 24 de mai de 2018 às 16:51, Moritz Tobiasch <moritztobiasch using gmail.com <mailto:moritztobiasch using gmail.com>> escreveu:
>> Yes. Wolfgang is right about everything, and in addition, I forgot to mention that the log transform command needs the {scales} package. So please
>> - avoid my mistakes and follow Wolfgangs suggestions
>> - load the scales package by adding library(scales) first
>> - accept my sincerest apologies
>> 
>> Cheers
>> Moritz
>> 
>> > Am 24.05.2018 um 21:38 schrieb Emerson M. Del Ponte <delponte using ufv.br <mailto:delponte using ufv.br>>:
>> >
>> > Dear Moritz
>> >
>> > As a ggplot user, I tried to use your code and got the same issues as
>> > Wolfgang. Can you send a fully reproducible code and the link to see the
>> > plot that you obtained using your code?
>> >
>> > Cheers,
>> > Emerson
>> >
>> >
>> > Emerson Medeiros Del Ponte
>> > Associate Professor & Graduate Studies Chair
>> > Departamento de Fitopatologia, Universidade Federal de Viçosa
>> > Viçosa MG Brasil  +55 (31) 3899-1103
>> > -------------------------------------------------------------
>> > Editor in Chief for Tropical Plant Pathology
>> > www.sbfitopatologia.org/tpp <http://www.sbfitopatologia.org/tpp>
>> > @TropPlantPathol
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > Em qui, 24 de mai de 2018 às 15:49, Viechtbauer, Wolfgang (SP) <
>> > wolfgang.viechtbauer using maastrichtuniversity.nl <mailto:wolfgang.viechtbauer using maastrichtuniversity.nl>> escreveu:
>> >
>> >> Dear Moritz,
>> >>
>> >> Thanks for the code. Unfortunately, it doesn't work for me. One problem
>> >> are the curly quotes (“) that R won't like. Also, 'sizex' needs to be
>> >> defined first. But after fixing that, this can't work. If I run:
>> >>
>> >> ggplot(plot.dat, aes(ablat, exp(yi)))
>> >> + geom_point(pch = 19, cex = 1.5 * sizex)
>> >>
>> >> then this is interpreted as two separate commands. This would work:
>> >>
>> >> ggplot(plot.dat, aes(ablat, exp(yi))) +
>> >> geom_point(pch = 19, cex = 1.5 * sizex)
>> >>
>> >> Then I also got:
>> >>
>> >> Error in log_trans() : could not find function "log_trans"
>> >>
>> >> At that point, I kind of gave up.
>> >>
>> >> Best,
>> >> Wolfgang
>> >>
>> >> -----Original Message-----
>> >> From: R-sig-meta-analysis [mailto:
>> >> r-sig-meta-analysis-bounces using r-project.org <mailto:r-sig-meta-analysis-bounces using r-project.org>] On Behalf Of Moritz Tobiasch
>> >> Sent: Tuesday, 22 May, 2018 23:01
>> >> To: r-sig-meta-analysis using r-project.org <mailto:r-sig-meta-analysis using r-project.org>
>> >> Subject: [R-meta] meta-regression scatterplot in ggplot2: code
>> >>
>> >> Dear metafor community,
>> >>
>> >> I recently had the very honour to dig through R code in order to set up a
>> >> meta-regression scatterplot in ggplot2. As this experience was …
>> >> interesting for me, but doesn’t warrant to be repeated by anyone else, I
>> >> allow myself to send my approach to this honorable mailing list, for
>> >> further use as deemed appropriate. @Wolfgang Viechtbauer: of course you may
>> >> add this code (if it seems worth it) to your code examples on
>> >> www.metafor-project.com <http://www.metafor-project.com/>.
>> >>
>> >> Calculations are closely based on and expand the example of a
>> >> meta-analytic scatterplot as shown on the website
>> >> http://www.metafor-project.org/doku.php/plots:meta_analytic_scatterplot <http://www.metafor-project.org/doku.php/plots:meta_analytic_scatterplot>
>> >>
>> >> In order to gain access to all necessary parameters, confidence interval
>> >> boundaries are extracted from the escalc() function by
>> >> plot.dat <- summary.escalc(dat)
>> >> which generates a data.table() with effect size yi, variance vi, standard
>> >> error and confidence interval boundaries ci.lb <http://ci.lb/> and ci.ub.
>> >>
>> >> The data can then be put in the ggplot() syntax as following:
>> >>
>> >> ggplot(plot.dat, aes(ablat, exp(yi)))
>> >> + geom_point(pch = 19, cex = 1.5 * sizex) # as, to my experience, ggplot()
>> >> will render dots smaller than the plot() function
>> >> + geom_linerange(aes(ymin = exp(plot.dat$ci.lb <http://ci.lb/>), ymax =
>> >> exp(plot.dat$ci.ub)), size = .25) # gives straight lines w/o brackets at
>> >> the ends. if „classical“ look is preferred, use geom_errorbar()
>> >> + scale_y_continuous(trans = log_trans(), limits = c(0.2, 1.6)) # for
>> >> adjustment of axes, see (as example) http://www.cookbook-r.com/Graphs/ <http://www.cookbook-r.com/Graphs/>
>> >> + xlab("Absolute Latitude“)
>> >> + ylab("risk ratio“)
>> >> + geom_hline(yintercept = 1, linetype = "dotted“) # draws the dotted line
>> >> at y = 1 for equal risk ratio
>> >> + geom_line(data = preds, aes(x = preds$ablat, y = preds$pred)) # plots
>> >> the regression line
>> >> + geom_line(data = preds, aes(x = preds$ablat, y = preds$ci.lb <http://ci.lb/>), linetype
>> >> = "dashed“) # plots the lower confidence interval boundary
>> >> + geom_line(data = preds, aes(x = preds$ablat, y = preds$ci.ub), linetype
>> >> = "dashed“) # plots the upper confidence interval boundary
>> >>
>> >> Labeling of individual data points was not in the scope of my work, but
>> >> could be done by the geom_text(aes(label = label)) command.
>> >>
>> >> Hope this helps.
>> >>
>> >> Cheers
>> >> Moritz
>> >>
>> >> --
>> >> Dr. med. Moritz Tobiasch
>> >>
>> >> Kirchgasse 22b
>> >> A-6020 Innsbruck
>> >> Austria
>> >>
>> >> Tel.: +43 650 5667954
>> >> moritztobiasch using gmail.com <mailto:moritztobiasch using gmail.com>
>> >> _______________________________________________
>> >> R-sig-meta-analysis mailing list
>> >> R-sig-meta-analysis using r-project.org <mailto:R-sig-meta-analysis using r-project.org>
>> >> https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis <https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis>
>> >>
>> >
>> >    [[alternative HTML version deleted]]
>> >
>> > _______________________________________________
>> > R-sig-meta-analysis mailing list
>> > R-sig-meta-analysis using r-project.org <mailto:R-sig-meta-analysis using r-project.org>
>> > https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis <https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis>
> 
> --
> Dr. Moritz Tobiasch
> 
> Kirchgasse 22b
> A-6020 Innsbruck
> Österreich
> 
> Tel.: +43 650 5667954
> moritztobiasch using gmail.com <mailto:moritztobiasch using gmail.com>
> 
> 
> 
> 
> 
> 
> 
> 

--
Dr. Moritz Tobiasch

Kirchgasse 22b
A-6020 Innsbruck
Österreich

Tel.: +43 650 5667954
moritztobiasch using gmail.com









-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-meta-analysis/attachments/20180524/e40a3a23/attachment-0006.html>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: r-script_metascatter.R
Type: application/octet-stream
Size: 2153 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-meta-analysis/attachments/20180524/e40a3a23/attachment-0001.obj>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-meta-analysis/attachments/20180524/e40a3a23/attachment-0007.html>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: metascatter-538.png
Type: image/png
Size: 24248 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-meta-analysis/attachments/20180524/e40a3a23/attachment-0004.png>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-meta-analysis/attachments/20180524/e40a3a23/attachment-0008.html>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: metascatter-bw.png
Type: image/png
Size: 28807 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-meta-analysis/attachments/20180524/e40a3a23/attachment-0005.png>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-meta-analysis/attachments/20180524/e40a3a23/attachment-0009.html>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: metascatter-errorbar.png
Type: image/png
Size: 26170 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-meta-analysis/attachments/20180524/e40a3a23/attachment-0006.png>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-meta-analysis/attachments/20180524/e40a3a23/attachment-0010.html>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: metascatter.png
Type: image/png
Size: 26005 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-meta-analysis/attachments/20180524/e40a3a23/attachment-0007.png>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-meta-analysis/attachments/20180524/e40a3a23/attachment-0011.html>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 873 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <https://stat.ethz.ch/pipermail/r-sig-meta-analysis/attachments/20180524/e40a3a23/attachment-0001.sig>


More information about the R-sig-meta-analysis mailing list