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]]
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 firstWhy not use a scatterplot? You are likely to draw incorrect conclusions if you look at a double y-axis plot alone. Hadley -- http://had.co.nz/
Yes, a scatterplot would be better. But for the sake of interest, is it possible to get the label for the secondary y-axis to appear? I have been playing around with it all day in an attempt to get it to work and have been unsuccessful. I would like to know if it is possible and/or what I am doing wrong/missing. On 18-Oct-07, at 4:54 PM, hadley wickham wrote:> 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 > > Why not use a scatterplot? You are likely to draw incorrect > conclusions if you look at a double y-axis plot alone. > > Hadley > > -- > http://had.co.nz/
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. >
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
I think 'usr' can be used to specify the extent of the plotting region. So it is useful if, say, you are creating a multiplot window and want to scale all plots for comparison. I think that (for multiplots) xlim has limited usefulness. On 23-Oct-07, at 10:12 PM, Dave Hewitt wrote:> No problem. I still think it's too bad that mtext can't handle > reading direction changes. Seems simple to implement, and mtext is > a lot easier to understand than text. I remain confused about 'usr' > in par. > > d >