[R] draw borders of bars inside of the rectangles in a barplot

Bert Gunter bgunter@4567 @ending from gm@il@com
Mon May 21 17:10:37 CEST 2018


As I read ?barplot, the answer is no. I suspect the same is true in ggplot
and lattice, but you would have to check. If correct, this means you would
explicitly have to use the "width" argument to narrow or widen the bars
appropriately. Or maybe try something like:

barplot(x, beside=T, border= "black", space=c(0.08,1), col=rep(c('gray50',
'white'),5))

instead.

Cheers,
Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Mon, May 21, 2018 at 7:59 AM, Martin Batholdy via R-help <
r-help at r-project.org> wrote:

> Dear R-users,
>
> I want to draw a barplot with beside=TRUE.
> One halve of the bars are drawn with a border, while the other halve are
> drawn without a border (i.e. filled bars vs. non-filled bars next to each
> other).
>
> Because borders are drawn around the bars, doing this leads to one halve
> of the bars being wider than the other halve, expanding across the 0-point
> of the y-axis.
> This problem emerges especially with small figures and rather large border
> width.
>
> Now my question:
> Is there a way to draw the border inside of the bars instead of
> surrounding the bars? (similar to border-drawing options in graphics
> software, like photoshop or inkscape).
>
>
> Here some example code:
>
> x <- matrix(c(1:10), 2,5)
> par(lwd = 5)
> barplot(x, beside=T, border=rep(c(NA, 'black'),5), space=c(0.08,1),
> col=rep(c('black', 'white'),5))
>
>
>
> Thank you!
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list