[R] Aligning axis values when plotting more than one graph on same axes

Greg Snow Greg.Snow at imail.org
Mon Jun 15 23:19:52 CEST 2009


Here are 3 approaches:

barplot( 1:12, xlim=c(0,12), width=1, space=0, names.arg=substr(month.abb,1,1))
lines( (1:12) - 0.5, 1:12, type='b', lwd=2, col='red' )

### or

tmp <- barplot(1:12, names.arg=substr(month.abb, 1,1))
lines( tmp, 1:12, type='b', lwd=2, col='red' )


### or 

library(TeachingDemos)
tmp <- barplot(1:12, names.arg=substr(month.abb, 1,1))
updateusr( tmp[1:2], 0:1, 1:2, 0:1 )
lines( 1:12, 1:12, type='b', lwd=2, col='red' )




-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: Steve Murray [mailto:smurray444 at hotmail.com]
> Sent: Monday, June 15, 2009 3:03 PM
> To: Greg Snow; r-help at r-project.org
> Subject: RE: [R] Aligning axis values when plotting more than one graph
> on same axes
> 
> 
> Thanks for the replies.
> 
> This is a simple example which demonstrates exactly the problems I'm
> facing. As you can see, neither the x or y axes line up consistantly.
> 
> > barplot(1:12, names.arg=substr(month.abb, 1,1))
> > par(new=TRUE)
> > plot(1:12, 1:12, type="b", lwd=2, col="red", xaxt="n")
> 
> 
> I'd be surprised if there isn't a solution to this, seeing as they're
> two essential graph types in the base package?
> 
> Any pointers would be most welcome!
> 
> Thanks again,
> 
> Steve
> 
> 
> _________________________________________________________________
> Get the best of MSN on your mobile
> http://clk.atdmt.com/UKM/go/147991039/direct/01/




More information about the R-help mailing list