How does one label a 100% stacked bar chart, like the one that follows, with appropriate values in the stack?
# dummy data
dat <- data.frame(
Banner=c(rep("Company A",5),rep("Company B",5)),
Response=factor(c(1:5,1:5)),
Proportion=c(10,20,40,20,10,10,30,40,10,10))
dat <- rbind(dat,dat,dat)
dat$Time <- c(rep("Time 1",10),rep("Time 2",10),rep("Time 3",10))
I can get this to plot, without labels, no problem:
ggplot(dat, aes(Banner, Proportion, fill=Response)) +
geom_bar(position="stack", stat="identity") +
facet_grid(~Time)
However, what I need to do is label each element, preferrably in the center of the element. I remember seeing a function using ddply (I think it was Ramnath's answer), but for the life of me I can't find it.
Something like:
dat <- ddply(dat, .(Banner, Time), function(x) {
x$Pos <- cumsum(x$Proportion) # at top of element, want middle!
x})