Skip to content

additional axis, different scale

6 messages · pannigh, Jim Lemon, John Kane +1 more

#
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.
#
On 05/10/2012 09:37 PM, pannigh wrote:
Hi pannigh,
Have a look at twoord.plot (plotrix)
Jim
#
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
____________________________________________________________
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
#
Hi Jim, hi John,

thank you very much for your tips. The "plotrix" package solves the problem! 
However, thank you also for the advice that my way of plotting the data
might not be the best. I will think about it.

So once again thanx !

--
View this message in context: http://r.789695.n4.nabble.com/additional-axis-different-scale-tp4623210p4623313.html
Sent from the R help mailing list archive at Nabble.com.
#
On May 10, 2012, at 8:07 AM, John Kane wrote:

            
There is:

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))
par(new=TRUE)
plot(a,ba,type="b", pch=21, cex=2, col=2, lwd=2, lty=1, xlim=c(0,45),  
yaxt="n")
  axis(4, at=c(seq(0,25,length=6)), lab=c(seq(0,25,length=6)),  
col.axis=2 )

# could also specify ylim of c(0,25) to the second plot call.

# probably want to have ylab="" in one or both of those plot calls, too.

But I do agree this can be considered deceptive plotting practice.
#
Oh,  yes of course.  Thanks.  

I really don't like dual plots. I ran into one a few days ago that looked to me to be very dubious but I don't have the raw data to replot it in another form.  It's a side issue so I'm not going to bother about it but is annoyed me.



John Kane
Kingston ON Canada
____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!