title: Stacked barplot showing count of distinct values in each column of a data frame
body: <p>Good day,</p>
  
  <p>I have a data frame such as:</p>
  
  <pre><code>sample.df = data.frame(a=c(-1,1,0,-1),b=c(2,NA,1,2),c=c(0,0,1,2),d=c(-1,-2,0,0))
  </code></pre>
  
  <p>and I would like to produce a stacked barplot for each column showing the number of times each unique values occurs in that column (ignoring NAs).</p>
  
  <p>My first thought is to create a new data frame with the possible values as the rownames (depicted here as Score) and the data values being the count of times that value occurs for that column:</p>
  
  <pre><code>Score  a  b  c  d
  2      0  2  1  0
  1      1  1  1  0
  0      1  0  2  0
  -1     2  0  0  1
  -2     0  0  0  1
  </code></pre>
  
  <p>I've tried using ddply, table and aggregate from other examples but don't see a way to get to that structure. </p>
  
  <p>My thought is that once I have that it should be straightforward to hand it to barplot to get the stacked barplot showing the number of occurrences of each value in each column.</p>
  
  <p>I appreciate any guidance you can give me.</p>
  
  <p>Thank you,</p>
  
  <p>Dave</p>
  
  <p><strong>To close the loop on this, here is where I ended up.</strong></p>
  
  <p>I used melt as suggested by tcash21 ("Score" wasn't in the original data just attributes a, b, c and d). Also, ggplot() gave me an error about using "y" and stat="bin" so I removed the assignment of "y" in the ggplot() call. Here are the steps I ended up taking to get to the desired plot:</p>
  
  <pre><code>sample.df = data.frame(a=c(-1,1,0,-1),b=c(2,NA,1,2),c=c(0,0,1,2),d=c(-1,-2,0,0))
  new.df&lt;-melt(sample.df)
  new.df&lt;-new.df[complete.cases(new.df),]
  new.df$Score&lt;-as.factor(new.df$value)
  ggplot(new.df, aes(x=variable, fill=Score)) + geom_bar()
  </code></pre>