Re: [R] Alignment of lines within barplot bars

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Mon, 18 Apr 2011 13:31:08 -0600

Sorry I took so long to get back on this, I have been out of town.

For your case you need to provide adjustments for both the x and y to updateusr, try this:

library(TeachingDemos)
tmp <- barplot(c(1.5,40),yaxt='n',names.arg=1:2,ylim=c(0,1.25*40)) axis(4)
tmp2 <- par('usr')
updateusr(tmp[1:2], tmp2[3:4], 1:2, c(0,0.022) ) points( 1:2, c(0.01, 0.02), pch=16 )
axis(2)

You can make further adjustments to the new y axis by changing the 0.022 in the updateusr call.

-- 
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 snowboarder101
> Sent: Friday, April 08, 2011 2:26 PM
> To: r-help_at_r-project.org
> Subject: Re: [R] Alignment of lines within barplot bars
>
> Thanks for the reply. I looked at this before as I saw you had posted
> this,
> but this either doesn't work in my situation, or I am using it wrong.
>
> Take the example in the function:
>
> tmp <- barplot(1:4)
> updateusr(tmp[1:2], 0:1, 1:2, 0:1)
> lines(1:4, c(1,3,2,2), lwd=3, type='b',col='red')
>
> But I want to use par(new=T) and plot(), so:
>
> tmp <- barplot(1:4)
> par(new=T)
> updateusr(tmp[1:2], 0:1, 1:2, 0:1)
> plot(1:4, c(1,3,2,2), lwd=3, type='b',col='red')
>
> The reason I do this is that the y-axis then corresponds to my plot()
> data.
> In my specific case, it's more like this:
>
> tmp <- barplot(c(1.5,40),yaxt='n',names.arg=1:2,ylim=c(0,1.25*40))
> axis(4)
> par(new=T)
> updateusr(tmp[1:2], 1:2)
> plot(1:2,c(0.01,0.02),xaxt='n',pch=16)
>
> I want those points in the middle of the bars... but I want to keep the
> y-axis labels from the second plot. the par(new=T) probably wipes out
> the
> coordinates, so I'm not sure how use this?
>
> Thanks Again.
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Alignment-
> of-lines-within-barplot-bars-tp2533115p3437369.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.
______________________________________________ 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.
Received on Mon 18 Apr 2011 - 19:36:20 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 18 Apr 2011 - 20:50:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive