2

I have used a stacked bar chart (with coord_flip) to try to compare distributions (this is one a several techniques I'm playing with) for a control and treatment group for pre and post test. Here is the plot:

enter image description here

and here is the code (Sorry it's not reproducible with no data set. If this is a problem I'll make up a reproducible data set as I can't share the real data):

m4 <- ggplot(data=v, aes(x=trt, fill=value))
m5 <- m4 +  geom_bar() + coord_flip() + 
      facet_grid(time~type) + scale_fill_grey()

How can I change the y axis (which is actually on the bottom dues to coord_flip) to percents so every bar is equal in length? So I want counts to become percents. I need some sort of transformation that I'm betting ggplot has or could easily be created and applied some how.

Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519

1 Answers1

2

You probably just want position_fill, by setting,

+ geom_bar(position = "fill")
joran
  • 169,992
  • 32
  • 429
  • 468
  • That's it: I was trying something like this [(LINK)](http://stackoverflow.com/questions/3695497/ggplot-showing-instead-of-counts-in-charts-of-categorical-variables) SO post but to no avail. I'll mark it correct in 10 minutes as you're too quick. – Tyler Rinker Mar 17 '12 at 16:00