[R] Barplot w/ single stacked bar

Muenchen, Robert A (Bob) muenchen at utk.edu
Thu Jan 24 16:48:42 CET 2008

Hi All,

I can get the barplot function to do many types of plots, stacked or
otherwise. However, I cannot get it to do a *single* stacked bar. I've
searched several books & listserv archives to no avail. I suspect I'm
missing the obvious from the help file!

I can reach my goal in ggplot2, although the relative heights of the
bar's pieces don't seem quite right (it does generate a warning):

y<-factor( c("Male","Male","Female") )
mydata <- data.frame(x,y)

#These are close to my goal:
qplot( x, y, fill=y, geom="bar", data=mydata)

# or
ggplot(mydata, aes(x=x, y=y, fill=y)) + geom_bar()

# But this places the bars beside each other rather than stack them.
barplot( table(mydata$y), beside=FALSE)


Bob Muenchen (pronounced Min'-chen), Manager 
Statistical Consulting Center
U of TN Office of Information Technology
200 Stokely Management Center, Knoxville, TN 37996-0520
Voice: (865) 974-5230 
FAX: (865) 974-4810
Email: muenchen at utk.edu
Web: http://oit.utk.edu/scc, 
News: http://listserv.utk.edu/archives/statnews.html

More information about the R-help mailing list