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 -- 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 06/11/02 12:40, Gregor Gawron wrote:>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.I haven't tried this, but how about plotting y1 against x as usual, then plot y2 (I assume) against x using points() or lines(), with a suitable choice of ylim, such as ylim=c(0,1), and then add the axis using axis(). -- Jonathan Baron, Professor of Psychology, University of Pennsylvania Home page: http://www.sas.upenn.edu/~baron R page: http://finzi.psych.upenn.edu/ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 <gregor.gawron at rmf.ch> writes:>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.I have something on this in my R notes: http://www.myatt.demon.co.uk Mark -- Mark Myatt -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 -- 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 >_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA -------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 11 Jun 2002 at 12:40, 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.I do not know if it is a pure coincidence, but I recently tried to make similar plot. As you did not get any strightforward answer, I decided to write down a little function, which can make such plot. I am sure it can be improved by more experienced programmers but it seems to work as I (and maybe also you:-) wish. #---------------------------------------------------------------------------- # graf na 2 osach y plot.yy<-function(x,yright,yleft, yylab=c("",""),znac=c(1,2),bar=c(1,2), linky=F, ...) { 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], ...) if (linky) lines(x,yright,col=bar[1], ...) axis(4,pretty(range(yright),10)) if(yylab[1]=="") mtext(deparse(substitute(yright)),side=4,outer=T,line=1) else mtext(yylab[1],side=4,outer=T,line=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) else mtext(yylab[2],side=2,line=2) if (linky) lines(x,yleft,col=bar[2], lty=2, ...) } *znac* is coding vector for pch, *bar* for col, *yylab* is character vector for axes labels and *linky* is for drawing lines. It gives you some warnings sometimes but it still works. Hope it helps.> > --- > Gregor Gawron > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. > -.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
What's wrong? I tried today's examples and just got only both labels printed one over the other. 1. Brian Ripley x <- 1:10 y <- rnorm(10) z <- runif(10, 1000, 10000) par(mar=c(5,4,4,4) + 0.1) # Leave space for z axis plot(x, y) par(new=T) plot(x, z, type="l", axes=F, bty="n", xlab="", ylab="") axis(4, at=pretty(range(z))) mtext(z, 4, 3) 2. Don MacQueen 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) platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 major 1 minor 5.0 year 2002 month 04 day 29 Helmut Sch?tz Biometrics Dep. Biokinet GmbH Nattergasse 4 A-1170 Vienna/Austria tel +43(0)1 4856969-77 fax +43(0)1 4856970-90 helmut.schuetz at chello.at -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._