title: Create summary value when using group_by and summarize
body: <p>I often want to show change given a baseline year. For example, how much has something changed since a given year as a percentage? The <code>gapminder</code> dataset provides an excellent example:</p>
  
  <p><a href="https://i.stack.imgur.com/7sNie.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7sNie.jpg" alt="change in population"></a></p>
  
  <p>To start to get the answer, you would <code>group_by</code> year and continent, and <code>summarize</code> the sum the the population. But how do you get a summary value that is the population of 1952? </p>
  
  <pre><code>library(gapminder)
  gapminder %&gt;%
    group_by(year, continent) %&gt;%
    summarize(tot_pop = sum(as.numeric(pop)),
              SUMMARY_VAL = POP_SUM_1952,
              CHG_SINCE_1952 = (tot_pop - SUMMARY_VAL ) / SUMMARY_VAL ) %&gt;%
    ggplot(aes(x = year, y = CHG_SINCE_1952, color = continent)) +
    geom_line()
  </code></pre>
  
  <p>FYI, gapminder looks like this:</p>
  
  <pre><code># A tibble: 1,704 x 6
     country     continent  year lifeExp      pop gdpPercap
     &lt;fct&gt;       &lt;fct&gt;     &lt;int&gt;   &lt;dbl&gt;    &lt;int&gt;     &lt;dbl&gt;
   1 Afghanistan Asia       1952    28.8  8425333      779.
   2 Afghanistan Asia       1957    30.3  9240934      821.
   3 Afghanistan Asia       1962    32.0 10267083      853.
   4 Afghanistan Asia       1967    34.0 11537966      836.
   5 Afghanistan Asia       1972    36.1 13079460      740.
   6 Afghanistan Asia       1977    38.4 14880372      786.
   7 Afghanistan Asia       1982    39.9 12881816      978.
   8 Afghanistan Asia       1987    40.8 13867957      852.
   9 Afghanistan Asia       1992    41.7 16317921      649.
  10 Afghanistan Asia       1997    41.8 22227415      635.
  # ... with 1,694 more rows
  </code></pre>