title: ggplot2 in R: use `geom_ribbon` for shading under two different `geom_smooth` lines
body: <p>Using <a href="https://www.dropbox.com/sh/5poh0gpoq0wa4du/AABMmRpObK9fv7Xy7HzaC-QYa?dl=0" rel="nofollow noreferrer">this dataset</a>, I created this graph:</p>
  
  <p><a href="https://i.stack.imgur.com/qfoGY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qfoGY.png" alt="A graph for seconds vs age of a race, with blue points representing males and pink females"></a></p>
  
  <p>I wish to shade under the <code>geom_smooth</code> lines, like so:</p>
  
  <p><a href="https://i.stack.imgur.com/gy2rs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gy2rs.png" alt="The same graph, but with shading below a &lt;code&gt;geom_smooth&lt;/code&gt; line for the entire dataset."></a></p>
  
  <p>I want points only under the blue line or only under the pink line to have those colors, and everything under both lines to be dark-grey.</p>
  
  <p>I used this code to create the graph:</p>
  
  <pre><code>p3 &lt;- ggplot(df, aes(x = SECONDS, y = AGE, color = GENDER)) +
  geom_point() + theme_fivethirtyeight_mod() + ggtitle('Seconds vs. Age') +
  geom_hline(yintercept = 0, size = 1.2, colour = "#535353") + 
  geom_vline(xintercept = 0, size = 1.2, colour = "#535353") +
  geom_smooth(se = F) +
  geom_ribbon(aes(ymin = 0, ymax = predict(loess(AGE ~ SECONDS))), alpha = 1)
  </code></pre>
  
  <p>The code for <code>theme_fivethirtyeight_mod()</code> is this:</p>
  
  <pre><code>require(ggplot2)
  require(ggthemes)
  require(ggrepel)
  require(grid)
  require(gtable)
  
  theme_fivethirtyeight_mod &lt;- function (base_size = 12, base_family = "sans") {
  (theme_foundation(base_size = base_size, base_family = base_family) + 
   theme(line = element_line(colour = "black"),
         rect = element_rect(fill = ggthemes_data$fivethirtyeight["ltgray"], linetype = 0, colour = NA),
         text = element_text(colour = ggthemes_data$fivethirtyeight["dkgray"]), 
         axis.text = element_text(size = 11, colour = ggthemes_data$fivethirtyeight["dkgray"], face = "bold"),
         axis.ticks = element_blank(),
         axis.line = element_blank(), 
         axis.title = element_text(size = 11, colour = ggthemes_data$fivethirtyeight["dkgray"], face = "bold", vjust = 1.5),
         legend.title = element_blank(),
         legend.background = element_rect(fill="gray90", size=.5, linetype="dotted"),
         legend.position = "bottom",
         legend.direction = "horizontal",
         legend.box = "vertical", 
         panel.grid = element_line(colour = NULL),
         panel.grid.major = element_line(colour = ggthemes_data$fivethirtyeight["medgray"]), 
         panel.grid.minor = element_blank(),
         plot.title = element_text(hjust = 0.05, size = rel(1.5), face = "bold"), 
         plot.margin = unit(c(1, 1, 1, 1), "lines"),
         panel.background = element_rect(fill = "#F0F0F0"),
         plot.background = element_rect(fill = "#F0F0F0"),
         panel.border = element_rect(colour = "#F0F0F0"),
         strip.background = element_rect()))
  }
  </code></pre>
  
  <p>Thanks for all the help!</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>@MLavoie commented a link to a question that gave me a basic idea of how to shade under the <code>geom_smooth</code> lines by using a <code>predict(loess(AGE ~ SECONDS))</code>. <code>predict()</code> works like <code>geom_smooth</code>, and <code>loess</code> is the method used when <code>n &lt; 1000</code>.This enabled me to shade under the male and female lines, but did not allow me to find the area under both curves. The dark-grey shaded area is the area under the <code>geom_smooth</code> for the entire dataset.</p>
  
  <p>I suspect that to find the area under the male and female curves I would first need to capture the data from the <code>geom_smooth</code>s (male and female). I would then create a <code>data.frame</code> with the x-values as rows and a column for each set of y-values. I would find the minimum y-value for each x-value and I would shade the dark-grey underneath that curve.</p>
  
  <p>Interestingly, the shaded areas are outlined in a light blue, like the points, and the legend shows red or blue outlined boxes filled with a dark-grey color. I added this to the code instead of the original <code>geom_ribbon</code>:</p>
  
  <pre><code>geom_ribbon(data = df[df$GENDER == 'F',], aes(ymin = 0, ymax = predict(loess(AGE ~ SECONDS))), alpha = 1, fill = "red") +
  geom_ribbon(data = df[df$GENDER == 'M',], aes(ymin = 0, ymax = predict(loess(AGE ~ SECONDS))), alpha = 1, fill = "blue") +
  geom_ribbon(aes(ymin = 0, ymax = predict(loess(AGE ~ SECONDS))), alpha = 1)
  </code></pre>
  
  <p>That was the only new code involved in creating this graph:</p>
  
  <p><a href="https://i.stack.imgur.com/tH7yV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tH7yV.png" alt="A graph similar to the above, but with shading underneath &lt;code&gt;geom_smooth&lt;/code&gt; lines."></a></p>
  
  <p>In essence, I want to remove the blue outlines of the filled areas and I want to remove the dark-grey fill from the boxes in the legend, and if someone can figure out how I would love to shade the area underneath both lines. Thanks again!</p>