Plotting tables alsongside charts in R

[This article was first published on mages' blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Occasionally I’d like to plot a table alongside a chart in R, e.g. to present summary statistics of the graph itself. Thanks to the gridExtra package this is quite straightforward. The function tableGrob creates a table like plot of a data frame, while arrangeGrob allows me to arrange ggplot2, lattice and grid graphical objects (short ‘grobs‘, such as tableGrob) on a page.

Here is a little example:

Session Info

R version 3.1.3 (2015-03-09)<br />Platform: x86_64-apple-darwin13.4.0 (64-bit)<br />Running under: OS X 10.10.3 (Yosemite)<br /><br />locale:<br />[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8<br /><br />attached base packages:<br />[1] grid      stats     graphics  grDevices utils    <br />[6] datasets  methods   base     <br /><br />other attached packages:<br />[1] gridExtra_0.9.1 ggplot2_1.0.1  <br /><br />loaded via a namespace (and not attached):<br /> [1] colorspace_1.2-6 digest_0.6.8     gtable_0.1.2    <br /> [4] labeling_0.3     MASS_7.3-40      munsell_0.4.2   <br /> [7] plyr_1.8.1       proto_0.3-10     Rcpp_0.11.5     <br />[10] reshape2_1.4.1   scales_0.2.4     stringr_0.6.2   <br />[13] tools_3.1.3

To leave a comment for the author, please follow the link and comment on their blog: mages' blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)