Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overall Title for Plotting Window

If I create a plotting window in R with m rows and n columns, how can I give the "overall" graphic a main title?

For example, I might have three scatterplots showing the relationship between GPA and SAT score for 3 different schools. How could I give one master title to all three plots, such as, "SAT score vs. GPA for 3 schools in CA"?

like image 529
Ryan R. Rosario Avatar asked Aug 06 '09 20:08

Ryan R. Rosario


2 Answers

Using the traditional graphics system, here are two ways:

(1)

par(mfrow=c(2,2))
for( i in 1:4 ) plot(1:10)
mtext("Title",side=3,outer=TRUE,padj=3)

(2)

par(mfrow=c(2,2))
for( i in 1:4 ) plot(1:10)
par(mfrow=c(1,1),mar=rep(0,4),oma=rep(0,4))
plot.window(0:1,0:1)
text(.5,.98,"Title")
like image 67
hatmatrix Avatar answered Sep 30 '22 08:09

hatmatrix


The most obvious methods that come to my mind are to use either Lattice or ggplot2. Here's an example using lattice:

 library(lattice)
 depthgroup<-equal.count(quakes$depth, number=3, overlap=0)
 magnitude<-equal.count(quakes$mag, number=2, overlap=0)
 xyplot(lat ~ long | depthgroup*magnitude,
 data=quakes,
 main="Fiji Earthquakes",
 ylab="latitude", xlab="longitude",
 pch=".",
 scales=list(x=list(alternating=c(1,1,1))),
 between=list(y=1),
 par.strip.text=list(cex=0.7),
 par.settings=list(axis.text=list(cex=0.7)))

In lattice you would change the main= parameter.

The above example was lifted from here.

I don't have a good ggplot2 example, but there are a metricasston of examples with ggpolot2 over at the learn r blog.

One option might be this example where they use ggplot2 and

opts (title = "RSS and NINO3.4 Temperature Anomalies \nand SATO Index Trends Since 1980")

But you would have to have all three graphs created in gg2plot, naturally.

I think you should be fine with either lattice or ggplot2.

like image 29
JD Long Avatar answered Sep 30 '22 07:09

JD Long