[R] r: plots

Thomas Petzoldt thpe at hhbio.wasser.tu-dresden.de
Tue Feb 24 15:03:48 CET 2004


allan clark 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)


## Try something like:

fac <- 200

par(mar=c(5,4,4,5)+.1)

plot(x, ylim=range(c(x, y, fac * z)), col="blue", ylab="x, y")
points(y, col="green")
points(z*fac, col="red")

axis(4, at=pretty(z*fac), label=pretty(z*fac)/fac, ylab="z")
mtext("z", side=4, line=2.5)

# more about this see ?axis, ?pretty and ?mtext

Thomas P.

-- 
Thomas Petzoldt
Dresden University of Technology
Institute of Hydrobiology          petzoldt at rcs.urz.tu-dresden.de
01062 Dresden                      http://www.tu-dresden.de/fghhihb/




More information about the R-help mailing list