[R] additional axis, different scale

John Kane jrkrideau at inbox.com
Thu May 10 14:07:34 CEST 2012


I don't think there is any other way.  On the other hand, most gurus suggest that a dual scales on a graph are not a good thing.

What about using a two panel graph?

Quick rejigging of your code :
=================================================================
a  <- c(10, 20, 30, 40)
b  <- c(50, 250, 500, 600)
ba <- b/a

op  <-  par(las=1, mar=c(5,5,.5,5), mfrow=c(2, 1))
plot(a,b,     type="b", pch=22, cex=2, col=4, lwd=2, ylim=c(0,650),
xlim=c(0,45))
 plot (a,ba, type="b", pch=21, cex=2, col=2, lwd=2, lty=1)
par(op)
==================================================================



John Kane
Kingston ON Canada


> -----Original Message-----
> From: pannigh at gwdg.de
> Sent: Thu, 10 May 2012 04:37:37 -0700 (PDT)
> To: r-help at r-project.org
> Subject: [R] additional axis, different scale
> 
> Dear list,
> I am looking for a possibility to present results in a more graphical way
> by
> adding an axis. But I have trouble relating my data to the added axis.
> Imagine the following example:
> 
> a  <- c(10, 20, 30, 40)
> b  <- c(50, 250, 500, 600)
> ba <- b/a
> 
> par(las=1, mar=c(5,5,.5,5))
> plot(a,b,     type="b", pch=22, cex=2, col=4, lwd=2, ylim=c(0,650),
> xlim=c(0,45))
>   axis(4, at=c(seq(0,600,length=6)), lab=c(seq(0,25,length=6)),
> col.axis=2 )
>   lines(a,ba, type="b", pch=21, cex=2, col=2, lwd=2, lty=1)
> 
> I want the red line to relate its values to the x-axis (a) and axis 4 (on
> the right) and not as usual to the x-axis (a) and the y-axis (b).
> This would show the tendency of the red line much clearer which now can't
> be
> seen because of the very different scaling.
> E.g. I want R to know that I am trying to plot the first point of the red
> line P1(50/5) using the x-axis and the right axis, not the y-axis on the
> left ect.
> 
> I would like to solve this without using a factor solution like:
>   bb <-600/25 * ba
>   lines(a,bb, type="b", pch=21, cex=2, col=3, lwd=2, lty=1)
> 
> 
> For any kind of help I would be grateful !
> 
> --
> View this message in context:
> http://r.789695.n4.nabble.com/additional-axis-different-scale-tp4623210.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

____________________________________________________________
GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys
Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails



More information about the R-help mailing list