[R] Labelling a second y-axis

Jesse Sinclair sinclair.jesse at gmail.com
Thu Mar 22 02:14:49 CET 2007


Hi,
I am using the following code as an example function to create  
multiple y-axes on one plot. I have it working fine however, I can't  
seem to add a label on the second (right) axis. I have tried adding  
ylab="y2" in the axis call but, that didn't work; any ideas?

Thanks,

Jesse

Code:
function() {
	par(las=1,xaxs="r",mai=c(1,0.75,1,1))
	x<-1:10
	y1<-x
	y2<-x^2
	plot(x,y1,xlim=c(0,10),ylim=c(0,10),ylab="y1")
	title(main="Multiple Y-Axes in R",ylab="y2")
	par(new=TRUE)
	plot(x,y2,xlim=c(0,10),xaxt="n",yaxt="n",ylab="",pch=16)
	axis(4,at=c(0,20,40,60,80,100))
}



More information about the R-help mailing list