[R] Alignment of lines within barplot bars
Jim Lemon
jim at bitwrit.com.au
Fri Sep 10 12:18:36 CEST 2010
On 09/10/2010 01:35 AM, Steve Murray wrote:
>
> 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.
>
Hi Steve,
The barp function in the plotrix package centers the bars on integer
values and allows you to control the width of the bars (0.4 on each side
is the default). This would make it easier to calculate the values for
the segments function to superimpose te lines.
Jim
More information about the R-help
mailing list