Thanks, Carlos,
 
 your solution looks nice, however, there are 4 bars instead of 2 i.e. bars are 
not stacked.
Meanwhile I got a solution for that task.
So thanks for sharing your version of it!
 
Good luck,
 Mario


________________________________
Von: Carlos Ortega <c...@qualityexcellence.es>

Cc: "r-help@r-project.org" <r-help@r-project.org> 
Gesendet: 23:02 Samstag, 28.Januar 2012
Betreff: Re: [R] Horizontal stacked 100% bars with ggplot2


Hello,

If it helps...:



Lines <- "pet gender
dog male
dog female
dog male
cat female
cat female
cat male
"

d.f <- read.table(textConnection(Lines), header=T, as.is = TRUE)

d.tab<-table(d.f$pet, d.f$gender)
d.f.tab<-as.data.frame(table(d.f$pet, d.f$gender))
names(d.f.tab)<-c('pet','gender', 'Freq')


library(lattice)
histogram(
  ~ Freq | pet *gender, data=d.f.tab, 
  groups=gender, stack=T, horizontal=T
  )


Regards,
Carlos Ortega
www.qualityexcellence.es





Hello, R friends,
>
>I'm trying to crack this nut:
>
>
>Example Data.
>
>pet    gender
>dog    male
>dog    female
>dog    male
>cat    female
>cat    female
>cat    male
>
>Plot Task.
>
>Horizontal 100% bars where
>y axis shows gender factor (male vs. female)
>and x axis shows percentage of kind of pets (dog vs. cat)
>so that % dogs + % cats are stacked in 1 bar and sum up to 100% (for each 
>gender group 1 bar).
>
>How can this be done with ggplot2?
>
[[elided Yahoo spam]]
>
>Mario
>
>       [[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.
>
>
        [[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.

Reply via email to