Jason Horn
2007-Mar-13 19:34 UTC
[R] Adding bars to the right of existing ones using barplot
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
Petr Klasterecky
2007-Mar-13 20:06 UTC
[R] Adding bars to the right of existing ones using barplot
Add/subtract a small constant to/from your latter dataset (x-values) and plot it without axes. Petr Jason Horn napsal(a):> 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 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Petr Klasterecky Dept. of Probability and Statistics Charles University in Prague Czech Republic
Charilaos Skiadas
2007-Mar-13 20:25 UTC
[R] Adding bars to the right of existing ones using barplot
On Mar 13, 2007, at 3:34 PM, 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.Something like this? a<-rnorm(3,2,1) b<-rnorm(3,2,1) barplot(rbind(a,b), beside=TRUE) ?barplot for more options ( in particular, the height argument)> Thank you anyone who has the answer. > > - JasonHaris Skiadas Department of Mathematics and Computer Science Hanover College
Marc Schwartz
2007-Mar-13 22:04 UTC
[R] Adding bars to the right of existing ones using barplot
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. > > - JasonYou 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