[R] Stacked Bar Plot in ggplot2
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) dat I'm trying to create a stacked bar plot with the values for Clicks in the background and the values for conversions in the forefront. I tried the following, but because the values aren't factors, it's doesn't produce the right result. p3 = ggplot(dat, aes(as.character(date))) + geom_bar(aes(fill=as.factor(conv))) + ylim(c(0,70)) + geom_bar(aes(fill = conv), position = 'fill') p3 Help! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] Stacked Bar Plot in ggplot2
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 __ R-help@r-project.org mailing list 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.