Java Mailing List Archive

http://www.r-help.com/

Home » R Help for Statistical Computing »

[R] ggplot2 multiple group barchart

Waller Gregor (wall)

2010-09-01

Replies: Find Java Web Hosting

Author LoginPost Reply

hi there.. i got a problem with ggplot2.

here my example:

library (ggplot2)

v1 <- c(1,2,3,3,4)
v2 <- c(4,3,1,1,9)
v3 <- c(3,5,7,2,9)
gender <- c("m","f","m","f","f")

d.data <- data.frame (v1, v2, v3, gender)
d.data

x <- names (d.data[1:3])
y <- mean (d.data[1:3])


pl <- ggplot (data=d.data, aes (x=x,y=y))
pl <- pl + geom_bar()
pl <- pl + coord_flip()
pl <- pl + geom_text (aes(label=round(y,1)),vjust=0.5,
hjust=4,colour="white", size=7)
pl

this gives me a nice barchart to compare the means of my variables
"v1","v2" and "v3".
my question: how do i have to proceed if i want this barchart splittet
by the variable "gender".
so i get two small bars for "v1", one for female and one for male, two
bars for "v2" etc.
i need them all in one chart.

fill=gender, position="dodge" do not work...

any ideas?

thanks a lot

greg

______________________________________________
R-help@(protected)
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.
©2008 r-help.com - Jax Systems, LLC, U.S.A.