title: How to count and add total number of observations (n) to ggplot (geom_point)
body: <p>How do I display the total number of observations (n) in a <code>geom_point</code> plot? I know how to include the number by manually adding (e.g.) "n = 1000", but I want to be able to have the number of observations counted automatically for each figure and then displayed somewhere on the figure. </p>
  
  <p>Most of the code I've seen online is for adding n to boxplots (see example below). They don't seem to work for scatter plots (<code>geom_point</code>):</p>
  
  <pre><code>geom_text(aes(label=paste0("N = ", length(disabled)), 
  x=length(unique(disabled)), y=max(table(disabled)))) +
  </code></pre>
  
  <p>This is the code for my figure:</p>
  
  <pre><code>ggplot(scs, aes(x=year, y=disabled, color=unemployed, size=pop)) + 
  geom_point(aes(size=pop), alpha = 0.3) +
  labs(x = "Year",
      y = "Disabled",
      color = "Unemployed") +
  scale_size_continuous("Population size") +
  theme(
      axis.title.x = element_text(margin=margin(t=10)),
      panel.background = element_rect(fill=NA),
      legend.title = element_text(size=10),
      legend.key = element_blank())
  </code></pre>
  
  <p>When I add the <code>geom_point</code> code, it oddly changes the labeling of my size legend.</p>
  
  <p><strong>EDITED:</strong></p>
  
  <p>Thanks for the replies so far. Just to be clear, I don't want <em>n</em> broken down by groups. I want the total number of observations used in the figure. </p>
  
  <p>I don't know how to share my data but this is the output of dput(head(scs, 20)):</p>
  
  <pre><code>&gt; dput(head(scs, 20))
  structure(list(
  year = c(2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 
      2016, 2017, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013), 
  county_name = c("autauga", "autauga", "autauga", "autauga", "autauga", 
      "autauga", "autauga", "autauga", "autauga", "autauga", "autauga", 
      "autauga", "barbour", "barbour", "barbour", "barbour", "barbour", 
      "barbour", "barbour", "barbour"), 
  disabled = c(3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, 6, 
      6), 
  unemployed = c(4, 3, 3, 5, 10, 9, 8, 7, 6, 6, 5, 5, 6, 6, 6, 9, 
      14, 12, 12, 12), 
  pop = c(55036, 55036, 55036, 55036, 55036, 55036, 55036, 55036, 55036, 
      55036, 55036, 55036, 26201, 26201, 26201, 26201, 26201, 26201, 
      26201, 26201)), 
  row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", 
      "12", "25", "26", "27", "28", "29", "30", "31", "32"), 
  class = "data.frame")
  </code></pre>