title: R Setting Y Axis to Count Distinct in ggplot2
body: <p>I have a data frame that contains 4 variables: an ID number (<code>chr</code>), a degree type (<code>factor</code> w/ 2 levels of Grad and Undergrad), a degree year (<code>chr</code> with year), and Employment Record Type (<code>factor</code> w/ 6 levels).</p>
  
  <p>I would like to display this data as a count of the unique ID numbers by year as a stacked area plot of the 6 Employment Record Types.  So, count of <code>#</code> of ID numbers on the y-axis, degree year on the x-axis, the value of x being number of IDs for that year, and the fill will handle the Record Type. I am using <code>ggplot2</code> in <code>RStudio</code>.</p>
  
  <p>I used the following code, but the y axis does not count distinct IDs:</p>
  
  <pre><code>ggplot(AlumJobStatusCopy, aes(x=Degree.Year, y=Entity.ID,
         fill=Employment.Data.Type)) + geom_freqpoly() +
         scale_fill_brewer(palette="Blues",
         breaks=rev(levels(AlumJobStatusCopy$Employment.Data.Type)))
  </code></pre>
  
  <p>I also tried setting <code>y = Entity.ID</code> to <code>y = ..count..</code> and that did not work either.  I have searched for solutions as it seems to be a problem with how I am writing the <code>aes</code> code.</p>
  
  <p>I also tried the following code based on examples of similar plots:</p>
  
  <pre><code>ggplot(AlumJobStatusCopy, aes(interval)) + 
        geom_area(aes(x=Degree.Year, y = Entity.ID, 
                      fill = Employment.Data.Type)) +
        scale_fill_brewer(palette="Blues",
            breaks=rev(levels(AlumJobStatusCopy$Employment.Data.Type)))
  </code></pre>
  
  <p>This does not even seem to work.  I've read the documentation and am at my wit's end.</p>
  
  <p>EDIT:</p>
  
  <p>After figuring out the answer to the problem, I realized that I was not actually using the correct values for my Year variable.  A count tells me nothing as I am trying to display the rise in a lack of records and the decline in current records.</p>
  
  <p>My Dataset:<br>
  Year, int, 1960-2015<br>
  Current Record, num: % of total records that are current<br>
  No Record, num: % of total records that are not current</p>
  
  <p>Ergo each Year value has two corresponding percent values.  I am now using 2 lines instead of an area plot since the Y axis has distinct values instead of a count function, but I would still like the area under the curves filled.  I tried using Melt to convert the data from wide to long, but was still unable to fill both lines.  Filling is just for aesthetic purposes as I would like to use a gradient for each with 1 fill being slightly lighter than the other.</p>
  
  <p>Here is my current code:</p>
  
  <pre><code>ggplot(Alum, aes(Year)) + 
      geom_line(aes(y = Percent.Records, colour = "Percent.Records")) +
      geom_line(aes(y = Percent.No.Records, colour = "Percent.No.Records")) + 
      scale_y_continuous(labels = percent) + ylab('Percent of Total Records') + 
      ggtitle("Active, Living Alumni Employment Record") +
      scale_x_continuous(breaks=seq(1960, 2014, by=5))
  </code></pre>
  
  <p>I cannot post an image yet.</p>