Hi there,I'm having a difficult time setting up stacked barplots using ggplot2. I would like to do two things:1. Create a single stacked barplot in which the horizontal axis is "year" and the vertical axis is "amount" stacked by the "donor" category.2. Create a facet wrap barplot using the "donor" category as the facet typeHere is my data:year <- c(rep(c(1929:1978), each=9))donor <- c(rep(c("USSR","US","Germany","China","Japan","UN","WB","ADB","UK"), each=50))amount <- c(82000000, 47000000, 59000000, 77000000, 48000000, 59000000, 19000000, 73000000, 81000000,68000000, 6000000, 42000000, 84000000, 35000000, 44000000, 1000000, 1000000, 68000000,19000000, 1000000, 36000000, 91000000, 16000000, 63000000, 77000000, 65000000, 11000000,88000000, 35000000, 86000000, 60000000, 66000000, 52000000, 95000000, 50000000, 1000000,42000000, 3000000, 95000000, 2000000, 5000000, 3000000, 63000000, 37000000, 89000000,30000000, 31000000, 71000000, 80000000, 54000000, 32000000, 21000000, 67000000, 86000000,75000000, 25000000, 70000000, 54000000, 59000000, 90000000, 80000000, 4000000, 98000000,93000000, 34000000, 46000000, 26000000, 20000000, 62000000, 90000000, 87000000, 51000000,84000000, 58000000, 8000000, 72000000, 52000000, 44000000, 50000000, 17000000, 23000000,73000000, 83000000, 51000000, 7000000, 74000000, 14000000, 39000000, 67000000, 10000000,50000000, 94000000, 48000000, 2000000, 54000000, 11000000, 15000000, 89000000, 20000000,5000000, 8000000, 79000000, 7000000, 39000000, 51000000, 24000000, 63000000, 96000000,2000000, 59000000, 49000000, 4000000, 21000000, 20000000, 87000000, 63000000, 13000000,15000000, 16000000, 9000000, 26000000, 70000000, 82000000, 4000000, 73000000, 4000000,100000000, 65000000, 24000000, 92000000, 90000000, 33000000, 46000000, 70000000, 48000000,23000000, 93000000, 79000000, 100000000, 74000000, 26000000, 22000000, 30000000, 96000000,20000000, 61000000, 88000000, 94000000, 18000000, 29000000, 35000000, 49000000, 58000000,98000000, 13000000, 100000000, 75000000, 52000000, 93000000, 3000000, 96000000, 8000000,21000000, 27000000, 6000000, 89000000, 28000000, 99000000, 5000000, 63000000, 1000000,94000000, 58000000, 37000000, 92000000, 61000000, 85000000, 39000000, 90000000, 51000000,10000000, 61000000, 13000000, 68000000, 63000000, 68000000, 2000000, 57000000, 69000000,71000000, 89000000, 2000000, 47000000, 62000000, 24000000, 77000000, 32000000, 89000000,12000000, 16000000, 82000000, 50000000, 67000000, 75000000, 60000000, 24000000, 95000000,32000000, 97000000, 38000000, 33000000, 9000000, 95000000, 20000000, 3000000, 49000000,75000000, 83000000, 87000000, 38000000, 37000000, 87000000, 5000000, 15000000, 74000000,64000000, 1000000, 16000000, 87000000, 69000000, 54000000, 33000000, 26000000, 79000000,3000000, 15000000, 62000000, 21000000, 43000000, 81000000, 16000000, 46000000, 46000000,26000000, 79000000, 47000000, 42000000, 1000000, 65000000, 23000000, 7000000, 96000000,48000000, 13000000, 18000000, 18000000, 54000000, 23000000, 81000000, 65000000, 97000000,29000000, 53000000, 9000000, 80000000, 55000000, 15000000, 34000000, 39000000, 92000000,21000000, 94000000, 21000000, 30000000, 78000000, 37000000, 68000000, 92000000, 47000000,10000000, 65000000, 8000000, 31000000, 33000000, 39000000, 58000000, 89000000, 85000000,32000000, 84000000, 90000000, 99000000, 9000000, 5000000, 87000000, 85000000, 41000000,93000000, 14000000, 74000000, 50000000, 18000000, 4000000, 78000000, 16000000, 31000000,63000000, 59000000, 77000000, 36000000, 65000000, 25000000, 34000000, 18000000, 20000000,14000000, 94000000, 59000000, 63000000, 38000000, 13000000, 99000000, 50000000, 6000000,14000000, 41000000, 55000000, 26000000, 17000000, 5000000, 88000000, 63000000, 19000000,99000000, 42000000, 30000000, 2000000, 90000000, 76000000, 77000000, 61000000, 28000000,10000000, 63000000, 98000000, 36000000, 38000000, 87000000, 38000000, 65000000, 15000000,36000000, 37000000, 54000000, 10000000, 88000000, 24000000, 76000000, 20000000, 81000000,8000000, 98000000, 85000000, 27000000, 85000000, 14000000, 38000000, 54000000, 79000000,1000000, 66000000, 8000000, 92000000, 89000000, 60000000, 61000000, 98000000, 80000000,96000000, 18000000, 9000000, 57000000, 75000000, 36000000, 59000000, 87000000, 12000000,1000000, 8000000, 64000000, 24000000, 91000000, 57000000, 18000000, 12000000, 40000000,33000000, 34000000, 92000000, 1000000, 86000000, 52000000, 71000000, 49000000, 20000000,76000000, 91000000, 91000000, 16000000, 21000000, 43000000, 81000000, 56000000, 41000000,36000000, 21000000, 60000000, 56000000, 29000000, 36000000, 43000000, 52000000, 45000000,81000000, 43000000, 90000000, 100000000, 89000000, 41000000, 43000000, 46000000, 100000000,65000000, 94000000, 86000000, 13000000, 36000000, 52000000, 20000000, 57000000, 8000000,73000000, 48000000, 26000000, 61000000, 18000000, 43000000, 99000000, 39000000, 25000000)
df <- data.frame(year, donor, amount)
I have tried the following sets of code in trying to create a stacked barplot or facet wrap barlot and received the following errors:ggplot(amount, aes(year, amount, fill=factor(donor)),legend=FALSE) + geom_bar(binwidth=1.0)Error: ggplot2 doesn't know how to deal with data of class numericggplot(df, aes(year, amount, fill=factor(donor)),legend=FALSE) + geom_bar(binwidth=1.0)Error in pmin(y, 0) : object 'y' not foundggplot(df,aes(year),fill=donor) + geom_bar(aes(colour = donor, fill= donor), stat="identity",position = 'stack',binwidth=1)Error in pmin(y, 0) : object 'y' not foundggplot(amount, aes(x=year, fill=donor),legend=FALSE) + geom_bar(binwidth=1.0)Error: ggplot2 doesn't know how to deal with data of class integerggplot(df, aes(x=year, y=amount, fill=donor),legend=FALSE) + geom_bar(binwidth=1.0)Error in pmin(y, 0) : object 'y' not foundggplot(df, aes(x=year, y=amount,fill=factor(donor))) + geom_bar(binwidth=1.0) + facet_wrap(~donor)Error in pmin(y, 0) : object 'y' not foundAny help would be very much appreciated.--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
| From: | skhd...@gmail.com |
| To: | ggp...@googlegroups.com |
| Date: | 02/11/2013 04:38 PM |
| Subject: | Stacked & Facet Wrap Barplots in R Using ggplot2 |
| Sent by: | ggp...@googlegroups.com |
The chart analogue in Excel might not have pasted correctly. See attached.On Mon, Feb 11, 2013 at 6:20 PM, Sk Hd <skhd...@gmail.com> wrote:
Thanks very much for the response. It looks like your code doesn't actually stack the bars for the years that correspond with the amounts. I'm looking for something similar to this (as unattractive as this is!), and for a facet wrap barplot with the amounts corresponding to their associated years.