Josef.Kardos at phila.gov
2010-Jun-14 20:17 UTC
[R] how to make a barplot similar to Excel’s “clustered column chart”.
I have a matrix with 12 rows (one for each month), 2 columns (baseflow, runoff). I would like to make a barplot similar to Excel’s “clustered column chart”. Here is my matrix ‘x’ 8.258754 13.300710 10.180953 10.760465 11.012184 13.954887 10.910870 13.839839 9.023519 11.511129 7.189241 12.519830 5.925576 17.101491 5.211613 13.585175 5.039592 13.506304 4.462325 9.963006 5.586521 11.306202 7.739242 14.669374 If I use barplot(x, beside=T), column 1 appears on the left side of the plot, and then column 2 appears on the right side of the plot. I would rather that they alternate, so that for month 1, I see 2 bars – column 1, then column 2. And so forth for months 2-12. Is there a simple way to do this? (In excel this is the chart option for “clustered column”) [[alternative HTML version deleted]]
Peter Dalgaard
2010-Jun-14 20:37 UTC
[R] how to make a barplot similar to Excel’s “clustered column chart”.
Josef.Kardos at phila.gov wrote:> I have a matrix with 12 rows (one for each month), 2 columns (baseflow, > runoff). I would like to make a barplot similar to Excel???s ???clustered > column chart???. > Here is my matrix ???x??? > > 8.258754 13.300710 > 10.180953 10.760465 > 11.012184 13.954887 > 10.910870 13.839839 > 9.023519 11.511129 > 7.189241 12.519830 > 5.925576 17.101491 > 5.211613 13.585175 > 5.039592 13.506304 > 4.462325 9.963006 > 5.586521 11.306202 > 7.739242 14.669374 > > If I use barplot(x, beside=T), column 1 appears on the left side of the > plot, and then column 2 appears on the right side of the plot. I would > rather that they alternate, so that for month 1, I see 2 bars ??? column 1, > then column 2. And so forth for months 2-12. Is there a simple way to do > this? (In excel this is the chart option for ???clustered column???)Can't you just transpose x? barplot(t(x), beside=T) -- Peter Dalgaard Center for Statistics, Copenhagen Business School Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
Hrishi Mittal
2010-Jun-14 20:40 UTC
[R] how to make a barplot similar to Excel’s “clustered column chart”.
Josef, I think all you need to do is use the transpose of your data matrix. So if your dataset is called mydata: barplot(t(as.matrix(x)),beside=T) -- View this message in context: http://r.789695.n4.nabble.com/how-to-make-a-barplot-similar-to-Excel-s-clustered-column-chart-tp2254979p2255008.html Sent from the R help mailing list archive at Nabble.com.