[R] Adding bars to the right of existing ones using barplot

Marc Schwartz marc_schwartz at comcast.net
Tue Mar 13 23:04:10 CET 2007


On Tue, 2007-03-13 at 15:34 -0400, Jason Horn wrote:
> I'm trying to create a barplot that has two sets of data next to each  
> other.  I'm using barplot with the add=TRUE option, but this simply  
> adds the second dataset on top of the first, obscuring it.  How do I  
> add the new data to the right on the existing barplot so that both  
> sets are visible?  I've been playing with all sorts of option and  
> reading the list archives with no luck.
> 
> Thank you anyone who has the answer.
> 
> - Jason

You might want to take note of the 'space' argument in ?barplot:

 a <- 1:3
 b <- 4:6

 # concatenate the two vectors and specify
 # that the space before the 4th bar should be
 # wider

 barplot(c(a, b), space = c(1, 1, 1, 3, 1, 1))

Also take note that barplot() returns the bar midpoints, which can be
helpful if you want to add any additional annotation to the plot.  See
the examples in ?barplot.

HTH,

Marc Schwartz



More information about the R-help mailing list