[R] r: plots
Hanke, Alex
HankeA at mar.dfo-mpo.gc.ca
Tue Feb 24 16:04:28 CET 2004
How about:
x<-c(101,110,150,167,120)
y<-c(120,135,175,95,200)
z<-c(0.001, 0.15, 0.6, 0.8, 1)
plot(x,y,axes=T,xlab="",ylab="",pch="+")
par(new=T)
plot(x,z,axes=F,ylim=c(0,1))
axis(4, at=seq(0,1,.1), labels=seq(0,1,.1))
box()
> -----Original Message-----
> From: Duncan Murdoch [SMTP:dmurdoch at pair.com]
> Sent: Tuesday, February 24, 2004 6:10 AM
> To: allan clark
> Cc: Rhelp
> Subject: Re: [R] r: plots
>
> On Tue, 24 Feb 2004 14:44:47 +0200, allan clark
> <allan at stats.uct.ac.za> wrote :
>
> >hi all
> >
> >i have another probably simple question.
> >
> >I have three variables say x, y and z. x and y are quite large and z is
> >relative small.
> >how can one plot the three variables on the same graph with two separate
> >axis?
> >(one for x and y and the other for z)
> >
> >e.g.
> >x<-c(101,110,150,167,120)
> >y<-c(120,135,175,95,200)
> >z<-c(0.001, 0.15, 0.6, 0.8, 1)
>
> You need to do most of the work yourself:
>
> par(mar=par('mar')+c(0,0,0,2)) # make room for the extra axis
> plot(1:5, x, ylim = c(0, 200)) # plot x with room for the others
> points(1:5, y, pch=2) # plot y
> points(1:5, 200*z, pch=3) # plot z, magnified 200 times
> zticks <- pretty(z) # choose ticks for z
> axis(4, at=200*zticks, labels=zticks) # plot them
> mtext('z',side=4, line=3) # add the z label
>
> You'll also want to add a legend, but I'll let you figure that out.
>
> Duncan Murdoch
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list