For example we have usual stacked bar plot:
ggplot(diamonds, aes(x=color, fill=cut))+geom_bar(position="fill")

And I want to make same plot but leave on it only one of "Cut" - types. For example "Ideal" (purple one). Thus, it should be something like histogram of fraction of the Ideal diamonds among all other diamonds having same color. Can I do this within ggplot?
If you pre-summarize the data, it is straightforward:
library("plyr")
idl <- ddply(diamonds, .(color), summarize,
idealpct = sum(cut=="Ideal")/length(cut))
ggplot(idl, aes(x=color, y=idealpct)) +
geom_bar()

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With