[R] Plotting w/multiple y-axes?
Morten Sickel
Morten.Sickel at nrpa.no
Tue Jan 21 09:10:03 CET 2003
Per Bak wrote:
>How do I plot using multiple(2) y-axes?
>I have two series that use the same x-data, but have very different scales.
I don't know, it that is the only, or even the best way to do it, but I plot
with multiple Y-axes using the grid package. The problem I have found is
that you have to start using a completely new syntax for plotting
Morten
example:
# ywtext and yrtext are initialized to the text to be plotted at
# the 1st and 2nd Y axes
grid.newpage()
#1st series, scale 0 - 500:
push.viewport(viewport(yscale=c(0,500),w=.75,h=.75,xscale=xscale))
grid.points(unit(hillesoy$date,"native"),
unit(hillesoy$value,"native"),size=unit(3,"mm"),gp=gp.sw)
grid.xaxis(at=c(1990:2003),gp=gp.axis)
grid.yaxis(main=FALSE,gp=gp.axis)
grid.text(ywtext,x=unit(2004.8,"native"),rot=270,
gp=gp.text)
#2nd series, scale 0-250
push.viewport(viewport(yscale=c(0,250),xscale=xscale))
grid.lines(unit(sellafield$year,"native"),
unit(sellafield$amount,"native"),gp=gp.sella)
grid.yaxis(at=c(0,50,100,150,200,250),main=TRUE,gp=gp.axis)
grid.text(yrtext,x=unit(1988.3,"native"),rot=270,
More information about the R-help
mailing list