title: Error in ggplot.data.frame : Mapping should be created with aes or aes_string
body: <p>I am having a trouble while extracting the path from a <code>ggplot</code> and am stuck with an error. </p>
  
  <p>The image given below explains the result I am looking for: (Done in image editor for explaining purpose)</p>
  
  <p><a href="https://i.stack.imgur.com/3bc1g.png" rel="noreferrer"><img src="https://i.stack.imgur.com/3bc1g.png" alt="Image"></a></p>
  
  <p>Let's assume that Plot 1 is my original plot. What I am looking for is taking first point as 'F' point and traveling 24hrs from that point. </p>
  
  <pre><code>Des %&gt;%
     mutate(nf = cumsum(ACT=="F")) %&gt;%  # build F-to-F groups
  group_by(nf) %&gt;%
  mutate(first24h = as.numeric((DateTime-min(DateTime)) &lt; (24*3600))) %&gt;% # find the first 24h of each F-group
  ggplot(aes(x=Loq, y=Las)) + 
  geom_path(aes(colour=first24h)) + scale_size(range = c(1, 2))+ geom_point()
  
  Library(zoo)
  full.time = seq(Des$DateTime[1], tail(Des$DateTime, 1), by=600)   # new timeline with point at every 10 min
  d.zoo = zoo(Des[,2:3], Des$DateTime)        # convert to zoo object
  d.full = as.data.frame(na.approx(d.zoo, xout=full.time))  # interpolate; result is also a zoo object
  d.full$DateTime = as.POSIXct(rownames(d.full))
  </code></pre>
  
  <p><em>When I am using <code>na.approx</code> for interpolation it is giving me Error??</em> Otherwise not.</p>
  
  <blockquote>
    <p>Error in approx(x[!na], y[!na], xout, ...) : 
        need at least two non-NA values to interpolate
        In addition: Warning message:
        In xy.coords(x, y) : NAs introduced by coercion</p>
  </blockquote>
  
  <p>With these two <code>data.frame</code>s combined. Every F-F section is drawn in a separate plot and only the points not longer than 24h after the F-point is shown</p>
  
  <pre><code>library(dplyr)
  library(ggplot)
  
  Des %&gt;%
    select(ACT, DateTime) %&gt;%
    right_join(d.full, by="DateTime") %&gt;%
    mutate(ACT = ifelse(is.na(ACT),"",ACT)) %&gt;%
    mutate(nf = cumsum(ACT=="F")) %&gt;%
    group_by(nf) %&gt;%
    mutate(first24h = (DateTime-min(DateTime)) &lt; (24*3600)) %&gt;%
    filter(first24h == TRUE) %&gt;%
    filter(first24h == 1) %&gt;%
    ggplot(Des, aes(x=Loq, y=Las,colour=ACT)) +
    geom_path() + facet_wrap(~ nf)
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <blockquote>
    <p>Error in ggplot.data.frame(., Des, aes(x = Loq, y = Las, colour = ACT)) : 
        Mapping should be created with aes or aes_string</p>
  </blockquote>
  
  <p>This is my <code>Des</code> format:</p>
  
  <pre><code>ID  Las  Loq  ACT  Time  Date
  1  12    13   R  23:20 1-1-01
  1  13    12   F  23:40 1-1-01
  1  13    11   F  00:00 2-1-01
  1  15    10   R  00:20 2-1-01
  1  12    06   W  00:40 2-1-01
  1  11    09   F  01:00 2-1-01
  1  12    10   R  01:20 2-1-01
  so on...
  </code></pre>