Dear R users I am modifying a column chart which I have created in R using barplot to make it clearer. I have been able to change the settings to increase the width of the axes lines and the text size but I cannot find the code to change the width of the lines which create the bars/columns themselves. Can anyone point me in the right direction please? Many thanks Claire -- View this message in context: http://r.789695.n4.nabble.com/barplot-change-width-of-bar-outline-tp3569552p3569552.html Sent from the R help mailing list archive at Nabble.com.
barplot - change width of bar outline
5 messages · CAB, Rolf Turner, Marc Schwartz
On 03/06/11 10:26, CAB wrote:
Dear R users I am modifying a column chart which I have created in R using barplot to make it clearer. I have been able to change the settings to increase the width of the axes lines and the text size but I cannot find the code to change the width of the lines which create the bars/columns themselves. Can anyone point me in the right direction please?
As the code currently stands, it would appear that you *can't* change
the widths of the lines which create the bars.
However, it wouldn't be too hard to hack the code to make this
possible. One
thing that makes it slightly tricky is that the code allows for
cross-hatching
of the bars, and that is effected by the rect() function. The lwd argument
to rect() has an impact upon both the perimeter of the rectangle and
the cross-hatch lines. Presumably you don't want to increase the line width
of the latter. Hence you'd have to make two calls to rect() --- one to
draw the perimeter with the line width increased, and no cross-hatching,
and then again with the line width as usual and with the specification
of the
cross-hatching included.
The code for barplot.default() is all in raw R (no mucking around with
calls to .Internal() !!!) and is pretty straightforward, so the hack won't
be too hard to implement.
Good luck.
cheers,
Rolf Turner
On Jun 2, 2011, at 10:54 PM, Rolf Turner wrote:
On 03/06/11 10:26, CAB wrote:
Dear R users I am modifying a column chart which I have created in R using barplot to make it clearer. I have been able to change the settings to increase the width of the axes lines and the text size but I cannot find the code to change the width of the lines which create the bars/columns themselves. Can anyone point me in the right direction please?
As the code currently stands, it would appear that you *can't* change
the widths of the lines which create the bars.
However, it wouldn't be too hard to hack the code to make this possible. One
thing that makes it slightly tricky is that the code allows for cross-hatching
of the bars, and that is effected by the rect() function. The lwd argument
to rect() has an impact upon both the perimeter of the rectangle and
the cross-hatch lines. Presumably you don't want to increase the line width
of the latter. Hence you'd have to make two calls to rect() --- one to
draw the perimeter with the line width increased, and no cross-hatching,
and then again with the line width as usual and with the specification of the
cross-hatching included.
The code for barplot.default() is all in raw R (no mucking around with
calls to .Internal() !!!) and is pretty straightforward, so the hack won't
be too hard to implement.
Good luck.
cheers,
Rolf Turner
If you need the 'density' cross hatching, there is a workaround: par(lwd = 3) barplot(1:5, col = "white") par(lwd = 1) barplot(1:5, density = 10, add = TRUE) If you don't need the cross hatching, just use the first two lines. HTH, Marc Schwartz
Ummmm, addendum/correction. Forget what I said about cross-hatching.
Without realizing it, I was looking at my own personal/local version of
barplot.default, into which I'd built a cross-hatching capability. The
``real''
barplot.default doesn't have such a capability. Apparently R Core doesn't
approve of cross-hatching.
Anyhow, Mark Schwartz's workaround seems to accomplish what you want
without your having to do any code-hacking.
You should probably re-set par(lwd=1) after you've drawn your barplot()
irrespective of wanting to do any shading, to avoid surprises with line
widths
in later graphics.
cheers,
Rolf Turner
Thanks very much Rolf and Marc - this works great! Claire -- View this message in context: http://r.789695.n4.nabble.com/barplot-change-width-of-bar-outline-tp3569552p3571500.html Sent from the R help mailing list archive at Nabble.com.