Forest plots in R (ggplot) with side table

A friend asked me to help with a forest plot recently. After chatting about what she wanted the end result to look like, this is what I came up with.

grid.arrange(data_table, p, ncol=2)
## Warning: Removed 1 rows containing missing values (geom_point).

Some other options for forest plots included this:

From Abhijit blog. But I figured I’d start a fresh, and I’d already borrowed some code of Abhijits in the past for a survival curve.

The package rmeta offers two different versions. One with forestplot like so:

And one with metaplot like so:

Ultimately the two would be used for different purposes, and these examples shown are straight from the manual for rmeta.

It wasn’t too much work to create ‘another’ custom option to get what my friend wanted, so thought I’d share the code for anyone else interest. There was a little bit of ‘misdirection’ for lack of a better term to get it across the line, and I’m sure elements of this are sloppy. You can access the code on my github.

I wrote this post in RStudio using the R Markdown language and then knitr to turn in into markdown (.md), and then pandoc to turn it into html. The original file is available here on github.

system(“pandoc -s forest_plot.md -o forest_plot.html”)

About these ads

4 thoughts on “Forest plots in R (ggplot) with side table

    • Thanks Sophia. Right at the bottom of the post I link to this https://github.com/nzcoops/blog_code/blob/master/forest_plot.Rmd – if you run lines 7-50 (inclusive) that will generate the data, then run line 54 and you should see the plot. Let me know if there’s an issue. Enjoy. Oh, there will be an issue with some of the ggplot theme/element stuff being out of data but it should still run. Drop me a line if it doesn’t, I don’t have time to update at the moment :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s