[R] Stacked Bar Plot in ggplot2

Justin jtor14 at gmail.com
Tue Jul 19 21:23:46 CEST 2011


Abraham Mathew <abraham <at> thisorthat.com> writes:

> 
> I'm trying to develop a stacked bar plot in R with ggplot2.
> 
> My data:
> 
> conv = c(10, 4.76, 17.14, 25, 26.47, 37.5, 20.83, 25.53, 32.5, 16.7, 27.33)
> click = c(20, 42, 35, 28, 34, 48, 48, 47, 40, 30, 30)
> date = c("July 7", "July 8", "July 9", "July 10", "July 11", "July 12",
> "July 13",
> "July 14", "July 15", "July 16", "July 17")
> 
> dat <- data.frame(date=c(date), click=c(click), conv=c(conv),
> stringsAsFactors = FALSE)


Is: 
 ggplot(dat,aes(x=date))+geom_bar(aes(y=click),fill='red')+geom_bar(aes(y=conv),fill='blue')

what you're looking for?

or 

dat.melt<-melt(dat,'date')
ggplot(dat.melt,aes(x=date,y=value,fill=variable))+geom_bar()


Justin



More information about the R-help mailing list