[R] Drawing a rectangle around a barplot()
Barry Rowlingson
B.Rowlingson at lancaster.ac.uk
Thu Dec 2 12:07:03 CET 2004
michael watson (IAH-C) wrote:
> Hi
>
> I can't use box() as I don't
> want to draw a box round my entire plot, I just want to draw a box as
> the background to certain subsets of the bars.
One idea. Edit the barplot.default function so it doesnt call plot.new.
do:
myBarplot = barplot.default
then edit the myBarplot function. Add an extra parameter to the
argument list 'add', and make it False by default:
cex.names = par("cex.axis"), inside = TRUE, plot = TRUE,
axis.lty = 0, add=F, ...)
then find plot.new and wrap it in a condition:
if(!add)plot.new()
Now try:
tN <- table(Ni <- rpois(100, lambda=5))
myBarplot(tN)
rect(2,1,6.5,8.5)
- this puts the rectangle on top of the bars, which you dont want, so
you call myBarplot with add=T so that plot.new isnt called and the
barplot appears over the rectangle:
myBarplot(tN,add=T)
works for me, if I understand your problem correctly!
Baz
More information about the R-help
mailing list