title: How to better create stacked bar graphs with multiple variables from ggplot2?
body: <p>I often have to make stacked barplots to compare variables, and because I do all my stats in R, I prefer to do all my graphics in R with ggplot2. I would like to learn how to do two things:</p>
  
  <p>First, I would like to be able to add proper percentage tick marks for each variable rather than tick marks by count. Counts would be confusing, which is why I take out the axis labels completely.</p>
  
  <p>Second, there must be a simpler way to reorganize my data to make this happen. It seems like the sort of thing I should be able to do natively in ggplot2 with plyR, but the documentation for plyR is not very clear (and I have read both the ggplot2 book and the online plyR documentation. </p>
  
  <p>My best graph looks like this, the code to create it follows:</p>
  
  <p><img src="https://farm5.static.flickr.com/4016/4493625638_bb46924571_d.jpg" alt="example graph"></p>
  
  <p>The R code I use to get it is the following:</p>
  
  <pre><code>library(epicalc)  
  
  ### recode the variables to factors ###
  recode(c(int_newcoun, int_newneigh, int_neweur, int_newusa, int_neweco, int_newit, int_newen, int_newsp, int_newhr, int_newlit, int_newent, int_newrel, int_newhth, int_bapo, int_wopo, int_eupo, int_educ), c(1,2,3,4,5,6,7,8,9, NA), 
  c('Very Interested','Somewhat Interested','Not Very Interested','Not At All interested',NA,NA,NA,NA,NA,NA))
  
  ### Combine recoded variables to a common vector
  Interest1&lt;-c(int_newcoun, int_newneigh, int_neweur, int_newusa, int_neweco, int_newit, int_newen, int_newsp, int_newhr, int_newlit, int_newent, int_newrel, int_newhth, int_bapo, int_wopo, int_eupo, int_educ)
  
  
  ### Create a second vector to label the first vector by original variable ###  
  a1&lt;-rep("News about Bangladesh", length(int_newcoun))
  a2&lt;-rep("Neighboring Countries", length(int_newneigh))
  [...]
  a17&lt;-rep("Education", length(int_educ))
  
  
  Interest2&lt;-c(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17)
  
  ### Create a Weighting vector of the proper length ###
  Interest.weight&lt;-rep(weight, 17)
  
  ### Make and save a new data frame from the three vectors ###
  Interest.df&lt;-cbind(Interest1, Interest2, Interest.weight)
  Interest.df&lt;-as.data.frame(Interest.df)
  
  write.csv(Interest.df, 'C:\\Documents and Settings\\[name]\\Desktop\\Sweave\\InterestBangladesh.csv')
  
  ### Sort the factor levels to display properly ###
  
  Interest.df$Interest1&lt;-relevel(Interest$Interest1, ref='Not Very Interested')
  Interest.df$Interest1&lt;-relevel(Interest$Interest1, ref='Somewhat Interested')
  Interest.df$Interest1&lt;-relevel(Interest$Interest1, ref='Very Interested')
  
  Interest.df$Interest2&lt;-relevel(Interest$Interest2, ref='News about Bangladesh')
  Interest.df$Interest2&lt;-relevel(Interest$Interest2, ref='Education')
  [...]
  Interest.df$Interest2&lt;-relevel(Interest$Interest2, ref='European Politics')
  
  detach(Interest)
  attach(Interest)
  
  ### Finally create the graph in ggplot2 ###
  
  library(ggplot2)
  p&lt;-ggplot(Interest, aes(Interest2, ..count..))
  p&lt;-p+geom_bar((aes(weight=Interest.weight, fill=Interest1)))
  p&lt;-p+coord_flip()
  p&lt;-p+scale_y_continuous("", breaks=NA)
  p&lt;-p+scale_fill_manual(value = rev(brewer.pal(5, "Purples")))
  p
  update_labels(p, list(fill='', x='', y=''))
  </code></pre>
  
  <p>I'd very much appreciate any tips, tricks or hints. </p>