[R] r: plots

Duncan Murdoch dmurdoch at pair.com
Tue Feb 24 15:09:37 CET 2004

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
>(one for x and y and the other for z)
>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

More information about the R-help mailing list