Hidden Markov Model
2015-Jul-27 20:53 UTC
[R] Daily Category Revenue-Stacked Bar Chart in ggplot2
I am trying to use the ggplot2 to build a stacked bar chart for daily Revenue by category. The chart would look have date on the x-axis, and revenue on the y axis. The fill would be the categories themselves. I have searched a great deal and have been unable to find exactly how to do this. -- View this message in context: http://r.789695.n4.nabble.com/Daily-Category-Revenue-Stacked-Bar-Chart-in-ggplot2-tp4710431.html Sent from the R help mailing list archive at Nabble.com.
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
> -----Original Message-----
> From: hussain at touchofmodern.com
> Sent: Mon, 27 Jul 2015 13:53:30 -0700 (PDT)
> To: r-help at r-project.org
> Subject: [R] Daily Category Revenue-Stacked Bar Chart in ggplot2
>
> I am trying to use the ggplot2 to build a stacked bar chart for daily
> Revenue
> by category. The chart would look have date on the x-axis, and revenue on
> the y axis. The fill would be the categories themselves. I have searched
> a
> great deal and have been unable to find exactly how to do this.
>
>
>
> --
> View this message in context:
>
http://r.789695.n4.nabble.com/Daily-Category-Revenue-Stacked-Bar-Chart-in-ggplot2-tp4710431.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
____________________________________________________________
Can't remember your password? Do you need a strong and secure password?
Use Password manager! It stores your passwords & protects your account.
Hidden Markov Model
2015-Jul-29 18:23 UTC
[R] Daily Category Revenue-Stacked Bar Chart in ggplot2
Hi John, Great thanks for the examples! I am not sure what you are referring to when you say a post from Nabble - I posted this directly on R-help. I actually never heard of Nabble. Stacked Bar charts are great for when you have a lot of moving parts and need to be able to zero in on one of them (e.g. Advertising Placements). Unfortunately, I can't post the data since it is confidential. -- View this message in context: http://r.789695.n4.nabble.com/Daily-Category-Revenue-Stacked-Bar-Chart-in-ggplot2-tp4710431p4710540.html Sent from the R help mailing list archive at Nabble.com.