[R] Correctly plotting bar and scatter chart on 2-y axis plot with par(new=T)

Greg Snow Greg.Snow at imail.org
Thu Jul 1 02:42:30 CEST 2010


For 1 you can just reverse one of the y ranges, e.g.:

updateusr(1:2, range(0,y1), 1:2, rev(range(y2)) )

on my computer for some reason the axis command needs you to explicitly set the at points, but then it works properly.

For 2, are the axes on all the plots the same?  If so you can put all the axes in the outer margin and remove the space between the plots (see the pairs2 function in the TeachingDemos packages to see an example).

Otherwise you may need to remove some of the labeling from the plots and put it in the caption (publication) instead.  For on screen, just remember which plot is which.

A more detailed example of what you are trying may help us give better suggestions.

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


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of dan.weavesham
> Sent: Wednesday, June 30, 2010 12:44 PM
> To: r-help at r-project.org
> Subject: Re: [R] Correctly plotting bar and scatter chart on 2-y axis
> plot with par(new=T)
> 
> 
> Greg,
> 
> Just a quick one to say thanks for helping me out with my 2-y axis
> query --
> your solution works a treat.
> 
> However, 2 extension points I was wondering if you could help with:
> 
> - 1/ Is there any way to invert the 2nd y axis -- i.e. highest entry at
> the
> bottom of the axis? I can see that the updateusr takes a range as its
> input,
> but can't see a way to fix the values. Any thoughts?
> - 2/ I'm trying to organise 6 of these charts onto one plot using
> par(mfrow=c(2,3), oma = c(0.5,0,1,0)), etc. I'm drawing the 2nd y axis'
> label using mtext("Number of birds",  EAST <-4, at=55, line=2.25,
> cex=1,
> col="black"). Do you have any advice on how combine these charts into
> one
> chart, so that the x axis on each is legible (without resorting to the
> suggestion of "buy a very wide monitor" !!).
> 
> Thanks again.
> 
> Regards,
> 
> Dan
> --
> View this message in context: http://r.789695.n4.nabble.com/Correctly-
> plotting-bar-and-scatter-chart-on-2-y-axis-plot-with-par-new-T-
> tp2266589p2272763.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.



More information about the R-help mailing list