Draw borders within bars in barplot?
I'm drawing a simple barplot with thick bar borders:
par(lwd=3)
barplot(c(6,7))
arrows(0,0,10,0,lwd=1)
The borders stick out slightly over the x-axis, which looks bad.
Is there any way to draw th开发者_开发百科e border within each bar, rather than around it?
The best I can think of is to hack something together by hand by setting border = NA
in barplot
and then adding the borders using lines
:
par(lwd = 3, lend = 2)
barplot(c(6,7),border = NA)
lines(c(0.2,0.2,1.2,1.2),c(0.02,6,6,0.02))
lines(c(1.4,1.4,2.4,2.4),c(0.02,7,7,0.02))
This is far from ideal. The coordinates used in lines
assume the default 0.2 space between bars and pulling the bottom up to 0.02 was just based on me eyeballing it. You might have to tinker with it on a case by case basis.
My suggestion after failing to find a clip()-ping or an easy "inner border" answer is this suggestion:
opar <- par(lwd=3)
barplot(c(6,7))
arrows(0,0,10,0,lwd=3, col="grey")
par(opar)
It has the advantage that it doesn't clip the top of the higher bars. Bet you didn't notice that. I didn't notice it until I used lwd=10.
精彩评论