Hi to all, First of all, I prefer to tell that I am a R-newbie, so I apologize if this is a silly question (I have tried looking in the manuals, but without luck). I have two variables, y and z, that I want to plot against x in the same plot. I have done this before, using points() after plot(). But now the problem is that y and z are in different units of measurement, and their ranges are very different. I have tried drawing a second axis with axis(), but I found the same problem: the new axis is drawn in the same range than the first variable plotted in the y-axis. I would greatly appreciate some suggestions. Regards, Juan L. Cuervo _______________________________________________________________ Copa del Mundo de la FIFA 2002 El ?nico lugar de Internet con v?deos de los 64 partidos. ?Ap?ntante ya! en http://fifaworldcup.yahoo.com/fc/es/ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Juan Cuervo <juan_l_cuervo at yahoo.es> writes:> Hi to all, > First of all, I prefer to tell that I am a R-newbie, > so I apologize if this is a silly question (I have > tried looking in the manuals, but without luck). > I have two variables, y and z, that I want to plot > against x in the same plot. I have done this before, > using points() after plot(). But now the problem is > that y and z are in different units of measurement, > and their ranges are very different. > I have tried drawing a second axis with axis(), but I > found the same problem: the new axis is drawn in the > same range than the first variable plotted in the > y-axis. > I would greatly appreciate some suggestions. > Regards, > Juan L. CuervoThe trick is to rescale z into y coordinates, and then axis(3, at=..., labels=...) where "at" is in y coordinates, but the labels are given as z coordinates. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Gregor Gawron had the same problem 6 days ago and got the following solution. You can find more useful messages to other similar problems by looking at the archive. (http://cran.r-project.org/search.html and http://www.r-project.org/nocvs/mail/r-help/2002/summary.html) Suerte. Agus ################################################### Date: Tue, 11 Jun 2002 06:48:38 -0700 From: Don MacQueen <macq at llnl.gov> To: Gregor Gawron <gregor.gawron at rmf.ch>, r-help at stat.math.ethz.ch Subject: Re: [R] Different y-axes Here is an example: x <- 1:5 y1 <- 1:5 y2 <- 25:21 plot(x,y1) par(new=T) plot(x,y2,yaxt='n',col='blue') axis(4,y2) -Don At 12:40 PM +0200 6/11/02, Gregor Gawron wrote:>Hi All, > >I have checked everything I could find abot graphics, but still cannot >solve the problem. >Are there any ways to make a graph that plots two lines and two >different y-axes, each of them has a scale that is related to the >respective line. For example, y1 has a range 1:50 and y1 ranges 0:1. The >x-axe is the same for both. > >Thank you in advance. > >--- >Gregor Gawron >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- >r-help mailing list -- Readhttp://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html>Send "info", "help", or "[un]subscribe" >(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch >_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._Dr. Agustin Lobo Instituto de Ciencias de la Tierra (CSIC) Lluis Sole Sabaris s/n 08028 Barcelona SPAIN tel 34 93409 5410 fax 34 93411 0012 alobo at ija.csic.es On Mon, 17 Jun 2002, [iso-8859-1] Juan Cuervo wrote:> Hi to all, > First of all, I prefer to tell that I am a R-newbie, > so I apologize if this is a silly question (I have > tried looking in the manuals, but without luck). > I have two variables, y and z, that I want to plot > against x in the same plot. I have done this before, > using points() after plot(). But now the problem is > that y and z are in different units of measurement, > and their ranges are very different. > I have tried drawing a second axis with axis(), but I > found the same problem: the new axis is drawn in the > same range than the first variable plotted in the > y-axis. > I would greatly appreciate some suggestions. > Regards, > Juan L. Cuervo > > > _______________________________________________________________ > Copa del Mundo de la FIFA 2002 > El único lugar de Internet con vídeos de los 64 partidos. > ¡Apúntante ya! en http://fifaworldcup.yahoo.com/fc/es/ > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On 17 Jun 2002 at 15:16, Juan Cuervo wrote:> Hi to all, > First of all, I prefer to tell that I am a R-newbie, > so I apologize if this is a silly question (I have > tried looking in the manuals, but without luck). > I have two variables, y and z, that I want to plot > against x in the same plot. I have done this before, > using points() after plot(). But now the problem is > that y and z are in different units of measurement, > and their ranges are very different. > I have tried drawing a second axis with axis(), but I > found the same problem: the new axis is drawn in the > same range than the first variable plotted in the > y-axis. > I would greatly appreciate some suggestions. > Regards, > Juan L. Cuervo >Try this small function I made for myself (therefore it is not very well described). yylab is for right and left hand side axes labels znac is for pch bar is for col linky is for adding lines smooth is for smoothing actually it is very similar to prof.Ripley's answer. #---------------------------------------------------------------------------------------------- -------- # graf na 2 osach y plot.yy<-function(x,yright,yleft, yylab=c("",""),znac=c(1,2),bar=c(1,2), linky=F, smooth=0, ...) { par(mar=c(5,4,4,2),oma=c(0,0,0,3)) plot(x,yright,axes=F,ylab="",pch=znac[1],col=bar[1], ...) axis(4,pretty(range(yright),10)) if (linky) lines(x,yright,col=bar[1], ...) if (smooth!=0) lines(supsmu(x,yright,span=smooth),col=bar[1], ...) if(yylab[1]=="") mtext(deparse(substitute(yright)),side=4,outer=T,line=1, col=bar[1]) else mtext(yylab[1],side=4,outer=T,line=1, col=bar[1]) par(new=T) plot(x,yleft,ylab="",pch=znac[2],col=bar[2], ...) if(yylab[2]=="") mtext(deparse(substitute(yleft)),side=2,line=2, col=bar[2]) else mtext(yylab[2],side=2,line=2, col=bar[2]) if (linky) lines(x,yleft,col=bar[2], lty=2, ...) if (smooth!=0) lines(supsmu(x,yleft,span=smooth),col=bar[2], lty=2, ...) }> > _______________________________________________________________ > Copa del Mundo de la FIFA 2002 > El ?nico lugar de Internet con v?deos de los 64 partidos. > ?Ap?ntante ya! en http://fifaworldcup.yahoo.com/fc/es/ > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. > -.-.-.-.- r-help mailing list -- Read > http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", > or "[un]subscribe" (in the "body", not the subject !) To: > r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. > _._._._._Petr Pikal petr.pikal at precheza.cz p.pik at volny.cz -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._