[R] Alignment of lines within barplot bars

John Kane jrkrideau at yahoo.ca
Thu Sep 9 19:37:46 CEST 2010


Okay, I misread what you wanted.

Try this
======================================================
x <- 4:7
positions <- barplot(x)
mid <- x/2
arrows(positions-.5,mid,positions+.5,mid,angle=0)
======================================================
--- On Thu, 9/9/10, Steve Murray <smurray444 at hotmail.com> wrote:

> From: Steve Murray <smurray444 at hotmail.com>
> Subject: RE: [R] Alignment of lines within barplot bars
> To: jrkrideau at yahoo.ca, r-help at r-project.org
> Received: Thursday, September 9, 2010, 1:19 PM
> 
> Thanks for the reply.
> 
> However this isn't quite what I want. I'm looking to
> display a single horizontal line across each bar - the
> distance up the y-axis corresponding to the values of the
> object horiz_values.
> 
> So unless there's a way of controlling where the argument
> 'density' plots a particular line, then I don't think this
> is what I'm looking for.
> 
> Any other suggestions are very welcome.
> 
> Thanks again,
> 
> Steve
> 
> 
> ----------------------------------------
> > Date: Thu, 9 Sep 2010 10:01:26 -0700
> > From: jrkrideau at yahoo.ca
> > Subject: Re: [R] Alignment of lines within barplot
> bars
> > To: r-help at r-project.org;
> smurray444 at hotmail.com
> >
> > Like this?
> >
> > x <- 4:7
> > barplot(x, density=10, angle=180)
> >
> >
> >
> > --- On Thu, 9/9/10, Steve Murray  wrote:
> >
> >> From: Steve Murray 
> >> Subject: [R] Alignment of lines within barplot
> bars
> >> To: r-help at r-project.org
> >> Received: Thursday, September 9, 2010, 11:35 AM
> >>
> >> Dear all,
> >>
> >> I have a barplot upon which I hope to superimpose
> >> horizontal lines extending across the width of
> each bar. I
> >> am able to partly achieve this through the
> following set of
> >> commands:
> >>
> >> positions <- barplot(bar_values, col="grey")
> >> par(new=TRUE)
> >> plot(positions, horiz_values, col="red", pch="_",
> >> ylim=c(min(bar_values), max(bar_values)))
> >>
> >>
> >> ...however this results in small, off-centred
> lines, which
> >> don't extend across the width of each bar. I've
> tried using
> >> 'cex' to increase the width, but of course this
> also
> >> increases the height of the line and results in it
> spanning
> >> a large range of y-axis values.
> >>
> >>
> >> I'm sure this shouldn't be too tricky to achieve,
> nor that
> >> uncommon a problem! It may be that I'm taking the
> wrong
> >> approach.
> >>
> >> Any help offered would be gratefully received.
> >>
> >> Many thanks,
> >>
> >> Steve
> >>
> >>
> >>
> >>
> >>
> >> ______________________________________________
> >> 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