[R] Secondary Y axis title

Gabor Grothendieck ggrothendieck at gmail.com
Sat Oct 20 22:36:59 CEST 2007

That's strange.  When I run
its also cut off but if I run the very same code by copying and pasting it into
my session then its not cut off:

> packageDescription("zoo")$Version
[1] "1.4-0"
> R.version.string
[1] "R version 2.6.0 Patched (2007-10-08 r43124)"


opar <- par(mai = c(.8, .8, .2, .8))

plot(z[,1], type = "l",
   xlab = "X axis label", ylab = colnames(z)[1])
Waiting to confirm page change...

par(new = TRUE)

plot(z[,2], type = "l", ann = FALSE, yaxt = "n", col = "blue")


legend(x = "topleft", bty = "n", lty = c(1,1), col = c("black", "blue"),
       legend = paste(colnames(z), c("(left scale)", "(right scale)")))

usr <- par("usr")

# mtext line should replace text line if y labels are to have same orientation
#  mtext(colnames(z)[2], 4, 2, col = "blue")
text(usr[2] + .1 * diff(usr[1:2]), mean(usr[3:4]), colnames(z)[2],
   srt = -90, xpd = TRUE, col = "blue")


On 10/20/07, Dave Hewitt <dhewitt at vims.edu> wrote:
> I was curious about the exact same question that John Theal posed - how to
> get a second y-axis label for a plot of two data series against a common x
> (in my case, time).
> I tried two different methods - one in lattice and one in plot. Both times
> the y-axis on the right side appears but the label does not. Similar to
> John's comment, it appears that there is not enough room for the label.
> Gabor mentioned that the plot.zoo examples give a plot like this. When I
> run that series of examples, #7 appears to be what Gabor was referring to,
> but even there the label for the right-hand y-axis is missing.
> Help?
> Dave Hewitt

More information about the R-help mailing list