[R] Secondary Y axis title

Gabor Grothendieck ggrothendieck at gmail.com
Thu Oct 18 17:36:44 CEST 2007


One of the examples here shows two Y axes each with a label:

library(zoo)
example(plot.zoo)

On 10/18/07, John Theal <jtheal at bluewin.ch> wrote:
> I have the following R code to create a plot with two y axes.  I am
> essentially trying to
> plot a price series with a volume series on the same graph. (i.e. to
> compare price with volume).  I can label the first
> y axis successfully, but the problem is in labeling the 2nd y-axis.
> Essentially, the
> label never appears.  It seems as though there is not enough margin
> on the right hand
> side of the figure to contain the axis title.  I have tried adjusting
> the margins, but this
> just shrinks the graph within the quartz window and the title never
> appears.  Is there some
> way to adjust the space for text to the right of the secondary y axis?
>
>
> plot(x1,col="darkviolet", xlim=c(min(Duration),max
> (Duration)),ylab="Price", type="l", xaxs="i", xaxt="n")
>
> axis(2,col.axis="black")
>
> par(new=TRUE)
>
> plot(x2,col="green", xlim=c(min(Duration),max(Duration)), type="l",
> ylab="", axes=FALSE ,xaxs="i",xaxt="n", yaxt="n", pch=16, las=1)
>
> axis.Date(1,at=seq(as.Date("1986/01/15"),as.Date("2006/10/31"),by="1
> years"))
>
> axis(4,col.axis="black")
>
> text(locator(1), "2nd Y Axis Title", srt = 270, xpd = FALSE)
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list