Combining several lattice charts into one

[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.

Last week I mentioned the grid.arrange function of the gridExtra package that allows me to combine graphical grid objects onto one page. The latticeExtra package provides another elegant solution for trellis (lattice) plots: the function c.trellis() or just c() combines the panels of multiple trellis objects into one.

Here is minimal example from the help file of c.trellis:

library(latticeExtra)<br />## Combine different types of plots.<br />c(wireframe(volcano), contourplot(volcano))<br />

In my next example I am using data from Eurostat, the statistical office of the European Union, showing the use of public transport in four countries. The data can be accessed directly in R via the eurostat package; see also the package vignette.

Here I have two xyplot objects that I combine into one chart using a named vector. I know this is not the best way to present the data, but that is not the point here. Naming the elements in c() adds those names also into the panel strip. Very handy indeed!

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] stats     graphics  grDevices utils     datasets  methods  <br />[7] base     <br /><br />other attached packages:<br />[1] latticeExtra_0.6-26 lattice_0.20-31     RColorBrewer_1.1-2 <br />[4] eurostat_1.0.16    <br /><br />loaded via a namespace (and not attached):<br />[1] grid_3.1.3     plyr_1.8.1     Rcpp_0.11.5    reshape2_1.4.1<br />[5] stringi_0.4-1  stringr_0.6.2  tidyr_0.2.0    tools_3.1.3

To leave a comment for the author, please follow the link and comment on their blog: mages' blog. 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)