Reputation: 41
I'm having a problem using the par
option oma
to set a plot-wide title, when I have specified plot sizes using pin
. The oma
title is way way up (seems outside of the oma
range) when pin
is used; when pin
is commented out (as below) the oma
title location is visually appealing. I've tried rotating the sequence of par
options, thinking one might be over-riding the others, but no luck. Code is below. Clues appreciated! Thanks, Tom
par(mfrow=c(1,2)) # 1X2 graphs
par(oma=c(0,0,5,0)) # top has 5 lines of space
par(mar=c(4,4,2,1)+.1) # margin lines
#par(pin=c(1.9,1.9)) # plot areas for graphs
# plot 1
plot(rnorm(n=20),col="olivedrab",pch=19,ylim=c(-2.0,2.0),xlim=c(0,20),ylab="",xlab="")
mtext("Observation No.",side=1,line=3)
mtext("Random variate",side=2,line=3)
mtext("Olivedrab Plot",side=3,line=2,cex=1.5)
# plot 2
plot(rnorm(n=20),col="olivedrab2",pch=19,ylim=c(-2.0,2.0),xlim=c(0,20),ylab="",xlab="")
mtext("Observation No.",side=1,line=3)
mtext("Random variate",side=2,line=3)
mtext("Olivedrab Plot",side=3,line=2,cex=1.5)
mtext("Army Olive Drab Plots",side=3,line=3,cex=2,outer=TRUE) # add outer label
Upvotes: 4
Views: 27344
Reputation: 263451
You have not described what you want to see, only what code produces something you do not like. Guessing that you want to see mtext
produce a "main title" that is further away from the outer edge of the graphics device (closer to the graphs) I suggest you use a negative line number for placement. As the help page says, 'line' specifies "starting at 0 counting outwards" (although I was unable to find a description of where we should expect that zero-line to be.)
par(mfrow=c(1,2)) # 1X2 graphs
par(oma=c(0,0,5,0)) # top has 5 lines of space
par(mar=c(4,4,2,1)+.1) # margin lines
par(pin=c(1.9,1.9)) # plot areas for graphs
# plot 1
plot(rnorm(n=20),col="olivedrab",pch=19,ylim=c(-2.0,2.0),xlim=c(0,20),ylab="",xlab="")
mtext("Observation No.",side=1,line=3)
mtext("Random variate",side=2,line=3)
mtext("Olivedrab Plot",side=3,line=2,cex=1.5)
# plot 2
plot(rnorm(n=20),col="olivedrab2",pch=19,ylim=c(-2.0,2.0),xlim=c(0,20),ylab="",xlab="")
mtext("Observation No.",side=1,line=3)
mtext("Random variate",side=2,line=3)
mtext("Olivedrab Plot",side=3,line=2,cex=1.5)
mtext("Army Olive Drab Plots",side=3,line=-3,cex=2,outer=TRUE)
Upvotes: 3