[R] barplot plotting problem
Marc Schwartz
mschwartz at medanalytics.com
Fri Jan 17 14:21:03 CET 2003
> -----Original Message-----
> From: r-help-admin at stat.math.ethz.ch
> [mailto:r-help-admin at stat.math.ethz.ch] On Behalf Of Jeremy Butler
> Sent: Thursday, January 16, 2003 11:42 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] barplot plotting problem
>
>
> Hi,
> Is there any equivalent of type="n" when constructing
> barplots which will still construct the axes (plot=F, as it
> says doesn' plot anything at all). Alternatively I tried
> setting col="white" and border="white" but the border command
> does not seem to be operational. True??
>
> Any other ideas? What I'm actually trying to do is construct
> vertical abline()'s _behind_ my plotted data. It seems to me
> that this requires axes construction then abline plotting
> then data plotting. Fine for plot() etc. but I don't seem to
> be able to manage it when barplotting. Is there some other
> way to do this that I'm missing? Cheers, Jeremy
Jeremy,
There is not an equivalent in barplot to "type = n" in plot or "add =
TRUE" in boxplot. I will look into adding something like that in the
barplot2() function in the gregmisc package.
What you can do is something like:
mp <- barplot(1:5)
abline(v = mp)
par(new = TRUE)
barplot(1:5)
What this does is to draw the initial barplot and store the bar
midpoints in "mp". Using abline, you get vertical lines initially on
top of the bars at their midpoints. Setting par(new = TRUE) tells R to
not clear the plot window before the next call to barplot(). You then
redraw the barplot, such that now the bars are over the vertical lines
drawn by abline.
You can then make any adjustments you need in the axes if you wish.
Hope that helps.
Regards,
Marc
More information about the R-help
mailing list