[R] changing the limits of a secondary y-axis in a barplot
jim at bitwrit.com.au
Wed Nov 17 11:55:26 CET 2010
On 11/17/2010 03:06 PM, Anna.Richards at csiro.au wrote:
> I hope this is a simple question. I am having trouble changing the scale of a secondary y-axis on a barplot. When I run the code below the limits set for the first axis are always applied to the second axis as well. I am using the latest R version 2.12.0.
> For example, if I have 3 vectors (Y1, Y2, Y3), and Y1 and Y2 need to be plotted on the left axis and Y3 on the right axis:
> par(mfrow=c(1,1), mai=c(1.0,1.0,1.0,1.0))
> Plot1<-barplot(rbind(Y1,Y2), beside=T, axes=T, names.arg=c("a","b"),
> ylim=c(0,15), xlim=c(1,9), space=c(0,1), col=c("darkgray","white"))
> Plot2<-barplot(Y3, add=T, beside=T, names.arg="c",
> col=c("darkgray","white"), ylim=c(0,5), space=c(0,7), width=1)
> How can I change the barplot so that the left hand axis scales from 0 to 15 and the right hand axis from 0 to 5?
Have a look at the twoord.plot function in the plotrix package. This
does exactly what you describe above.
More information about the R-help