[R] barplot in ggplot2

Joshua Wiley jwiley.psych at gmail.com
Tue May 11 16:42:07 CEST 2010


Hello,

I am trying to make a barplot of means where the difference between
the barheights is a different color.  My goal is to convey the same
information as a dodged barplot, but with only four bars.  Below is
the data I am working with, and the two plots I have tried.  The
stacked plot would be great, if they were stacked in front of each
other.  Any ideas on how to do this would be appreciated.

Thanks,

Josh

##############################
plot.means <- structure(list(means = c(2.35, 1.8, 2.26086956521739,
1.90909090909091, 1.88333333333333, 1.73846153846154,
1.93333333333333, 1.75), hilow = c(0, 1, 0, 1, 0, 1, 0, 1), index =
c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L)), row.names = c(NA, -8L), .Names =
c("means", "hilow", "index"), class = "data.frame")

##Uncomment below if ggplot2 is not already loaded
#library(ggplot2)
ggplot(plot.means, aes(x=index, y=means, fill=factor(hilow))) +
geom_bar(position="dodge", stat="identity") #dodged plot
ggplot(plot.means, aes(x=index, y=means, fill=factor(hilow))) +
geom_bar(stat="identity") #stacked plot

##############################


--
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/



More information about the R-help mailing list