Murray Richardson
2008-May-03 19:29 UTC
[R] Stacked bar plot anomaly When column contains a negative and a positive value
Hello users, I've noticed a problem when creating a stacked column plot when a column contains a negative and a positive value. e.g. series1<-c(-1,-2, 3, 4, 5) series2<-c( 5, -4,-3,-2, 1) data<-rbind(series1,series2) barplot(as.matrix(data), beside=FALSE) In these cases (i.e. first, third and fifth columns) the plotting is not handled correctly. Compare this output with that of: barplot(as.matrix(data), beside=TRUE) Shouldn't the plots look the same except in the beside=FALSE scenario the constituent bars should not be juxtaposed but instead are one on top of the other? Thanks for any advice! Murray Richardson
Duncan Murdoch
2008-May-03 20:10 UTC
[R] Stacked bar plot anomaly When column contains a negative and a positive value
On 03/05/2008 3:29 PM, Murray Richardson wrote:> Hello users, > > I've noticed a problem when creating a stacked column plot when a column > contains a negative and a positive value. e.g. > > series1<-c(-1,-2, 3, 4, 5) > series2<-c( 5, -4,-3,-2, 1) > data<-rbind(series1,series2) > barplot(as.matrix(data), beside=FALSE) > > > In these cases (i.e. first, third and fifth columns) the plotting is not > handled correctly. Compare this output with that of:It doesn't make sense to stack values with mixed signs, but what barplot does appears to make sense. The first column has a bar of length -1 overplotted with a bar of length 5, which completely obscures it. What would you expect it to do? Duncan Murdoch> > > barplot(as.matrix(data), beside=TRUE) > > > Shouldn't the plots look the same except in the beside=FALSE scenario > the constituent bars should not be juxtaposed but instead are one on top > of the other? > > Thanks for any advice! > > Murray Richardson > > ______________________________________________ > R-help at r-project.org 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.
Murray Richardson
2008-May-03 20:16 UTC
[R] Stacked bar plot anomaly When column contains a negative and a positive value
Hello all Please ignore this last post as I now realize it is because the stacked components are summed, as they should be. I needed the columns to be stacked but not summed so just plotted the two series separately with add=T Sorry... Murray Richardson -------- Original Message -------- Subject: Stacked bar plot anomaly When column contains a negative and a positive value Date: Sat, 03 May 2008 15:29:41 -0400 From: Murray Richardson <murray.richardson at utoronto.ca> To: r-help at R-project.org Hello users, I've noticed a problem when creating a stacked column plot when a column contains a negative and a positive value. e.g. series1<-c(-1,-2, 3, 4, 5) series2<-c( 5, -4,-3,-2, 1) data<-rbind(series1,series2) barplot(as.matrix(data), beside=FALSE) In these cases (i.e. first, third and fifth columns) the plotting is not handled correctly. Compare this output with that of: barplot(as.matrix(data), beside=TRUE) Shouldn't the plots look the same except in the beside=FALSE scenario the constituent bars should not be juxtaposed but instead are one on top of the other? Thanks for any advice! Murray Richardson