title: How to ggplot two variables with a specific colour and legend with missing values
body: <p>I am trying to use <code>ggplot2</code> to plot two variables over time. The variables have missing values which differ. e.g:</p>
  
  <pre><code>       Date   Var1      Var2
  3 2016-06-16        NA    NA
  4 2016-06-17    0.0035 0.004
  5 2016-06-18        NA    NA
  6 2016-06-19    0.0825 0.083
  7 2016-06-20    0.0890    NA
  8 2016-06-21    0.1725 0.173
  </code></pre>
  
  <p>I want to plot this with <code>geom_point()</code> and the points connected by dotted lines and not leave gaps where there is missing data but also have a legend so I have the following:</p>
  
  <pre><code>plot1 &lt;- ggplot(mydata, aes(x=Date))
  
  plot1 &lt;- plot1 + geom_point(data= 
  mydata[!is.na(mydata$Var1),],aes(y= Var1, colour = 
  "Var1"), size =8, col = "navyblue") +
    geom_line(data= mydata[!is.na(mydata$Var1),],aes(y= Var1, 
  group =1, colour = "Var1"), linetype = 6, lwd = 1, col = "navyblue") +
    geom_point(data = mydata[!is.na(mydata$Var2),], aes(y=cal5C, colour 
  = "Var2"), size=8, col = "turquoise3") +
    geom_line(data = mydata[!is.na(mydata$Var2),],aes(y=Var2, group = 
  1, colour = "Var2"), linetype =6, col = "turquoise3")
  </code></pre>
  
  <p>Which works nicely both lines are plotted the desired colour with points and lines connecting and I can then adjust the theme etc. to make it look prettier.</p>
  
  <p>However a legend does not show - it does appear when I drop my colour specification i.e.:</p>
  
  <pre><code>plot1 &lt;- ggplot(mydata, aes(x=Date))
  plot1 &lt;- plot1 + geom_point(data= mydata[!is.na(mydata$Var1),],aes(y= 
  Var1, colour = "Var1"), size =8) +
    geom_line(data= mydata[!is.na(mydata$Var1),],aes(y= Var1, group =1, 
   colour = "Var1"), linetype = 6, lwd = 1) +
    geom_point(data = mydata[!is.na(mydata$Var2),], aes(y=Var2, colour = 
  "Var2"), size=8) +
    geom_line(data = mydata[!is.na(mydata$Var2),],aes(y=Var2, group = 1, 
  colour = "Var2"), linetype =6)
  </code></pre>
  
  <p>But I don't want to use the preset colours for my graph. I have seen people using the reshape package which I have tried but then I am not sure how to get the lines to connect between the points - the best I have is the the lines connect between all the points, which is not useful.  </p>
  
  <p>This is what I have using the reshape and melt to get it into long format:</p>
  
  <pre><code>library(reshape2)
  mydata2 &lt;- mydata[,c(1,26,28)] #subsets into 3 columns Date, Var1, Va2
  mydata.m &lt;- melt(mydata2, id.vars=c("Date"))
  head(mydata.m)
     Date  variable  value  
  1 2016-06-16 Var1     NA  
  2 2016-06-17 Var1  0.0035  
  3 2016-06-18 Var1      NA  
  4 2016-06-19 Var1  0.0825  
  5 2016-06-20 Var1  0.0890  
  6 2016-06-21 Var1  0.1725  
  </code></pre>
  
  <p>and then plotting it:</p>
  
  <pre><code>plot1 &lt;- ggplot(mydata.m, 
              aes(x=Date, y=value, color=variable))
  plot1 &lt;- plot1 + geom_point() + geom_line()               
  plot1 &lt;- plot1 + scale_color_manual(name="", values = 
  c("navyblue","turquoise3"))  
  </code></pre>
  
  <p>This plots just the points, a legend and the right colour but I cannot work out how to get the <code>geom_line()</code> to work - I have tried incorporating the <code>mydata.m[!is.na(mydata.m$value), ]</code> into the <code>geom_line()</code> after reshaping but it does not work and <code>geom_line(group = 2)</code> to no avail.</p>