Multiple levelplots with title and subtitle in R

October 23, 2012
By

(This article was first published on 0xCAFEBABE, and kindly contributed to R-bloggers)

I had quite a fight with R to put multiple levelplots with a shared title and subtite on the same chart, so I thought I put a PoC code here:
library(lattice)
m <- matrix(c(0.1,0.2,0.3,0.4), 2, 2)
col.l <- colorRampPalette(c('blue', 'green'))(30)

plot.new()
par(mfrow=c(2,2), oma=c(2,0,2,0))
print(levelplot(m, col.regions=col.l, main="L1"), split=c(1, 1, 2, 2))
print(levelplot(m, col.regions=col.l, main="L2"), split=c(1, 2, 2, 2), newpage=FALSE)
print(levelplot(m, col.regions=col.l, main="L3"), split=c(2, 1, 2, 2), newpage=FALSE)
print(levelplot(m, col.regions=col.l, main="L4"), split=c(2, 2, 2, 2), newpage=FALSE)
title("Centered Overall Title", outer=TRUE)
mtext(side=1, "Centered Subtitle", outer=TRUE)
The result should be something similar like this:

To leave a comment for the author, please follow the link and comment on his blog: 0xCAFEBABE.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.