Skip to content
Prev 353213 / 398498 Next

Daily Category Revenue-Stacked Bar Chart in ggplot2

First http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example and http://adv-r.had.co.nz/Reproducibility.html

Second. It is very annoying to have posts come in from Nabble. Very few R-help readers use it and the total context of some post to R-help is usually lost. If possible could you post directly to R-help.

We have no idea of what your problem is (see above) but here is a very simple example of a stacked barchart using ggplot2. And since I am already complaining I have included a side-by-side version of the barchart as well. I think that stacked barcharts are not a good idea unless obfuscation is the desired outcome. It is too hard to compare quantities with no common baseline.

Good luck.

dat1  <-  structure(list(dates = structure(c(1L, 2L, 3L, 4L, 5L, 1L, 2L, 
3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), .Label = c("1", 
"2", "3", "4", "5"), class = "factor"), revs = c(40, 7, 40, 20, 
35, 20, 15, 20, 15, 20, 15, 15, 35, 20, 20, 7, 7, 20, 7, 35), 
    typ....rep.LETTERS.1.2...10. = structure(c(1L, 2L, 1L, 2L, 
    1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
    2L), .Label = c("A", "B"), class = "factor")), .Names = c("dates", 
"revs", "typ....rep.LETTERS.1.2...10."), row.names = c(NA, -20L
), class = "data.frame")

#Stacked barchart
ggplot(dat1, aes(dates, revs, fill = typ)) + geom_bar(stat = "identity")


#Grouped or dodged barchart (I don't think these are the real names)
ggplot(dat1, aes(dates, revs, fill = typ)) + geom_bar(stat = "identity", position="dodge")


John Kane
Kingston ON Canada
____________________________________________________________
Can't remember your password? Do you need a strong and secure password?
Use Password manager! It stores your passwords & protects your account.