[R] plotting 2 y axes

David White dwhite at ling.ohio-state.edu
Tue Jun 26 17:51:36 CEST 2001


I'm plotting two y axes and have had good success using plot (specifying
axes=F and ann=F) then adding the y axis to the right with axis(4...) and
overlaying another plot (this time leaving the axis and labels in place.
My difficulty lies in getting a label for the right-side y-axis.

Here's the code I'm using:

 plot(spectrum[, 1], spectrum[, 2], xlim = xlim, ylim = ylim,
        type = "l", axes=F, ann=F)
    par(new = TRUE)
    plot(spectrum[, 1], preemp[, 2], xlim = xlim, ylim = ylim,
        type = "l", col = "red", ann = FALSE, axes=F)
    axis(4, labels=T, tick=T, ylim=ylim, ylab="Amplitude (dB)")
    abline(v = f1, lty = 3)
par(new = TRUE)
    ylim2 <- c(min(centroids[, 2]), max(centroids[, 2]))
    plot(centroids[, 1], centroids[, 2],
        xlim = xlim, ylim = ylim2, type="b", xlab="Freqeuncy (Hz)",
ylab="Percent total amplitude (%)")

Thanks in advance.


S. David White
sdavidwhite at bigfoot.com
Columbus, Ohio

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list