title: ggplot geom_point() with colors based on specific, discrete values
body: <p>I am trying to plot data points with three different colors for three value ranges. For example:</p>
  <pre><code>library(ggplot2)
  ggplot(mtcars, aes(wt, mpg)) + geom_point(aes(colour = qsec))
  </code></pre>
  <p>The above produces:</p>
  <p><img src="https://i.stack.imgur.com/Xn32km.png" alt="enter image description here" /></p>
  <p>Now, I would like to modify this so that qseq values &lt;17 are black, values between 17 and 19 are yellow and values above 19 are red. I've tried various approaches, but none of them seems to work:</p>
  <ul>
  <li><p>Taken from <a href="https://stackoverflow.com/q/13888222/1081936">here</a></p>
  <pre><code>  ggplot(mtcars, aes(wt, mpg)) + geom_point(aes(fill = qsec)) + 
    scale_fill_gradient(colours = c(&quot;black&quot;,&quot;yellow&quot;,&quot;red&quot;), 
    breaks=c(0,17,19), labels = format(c(&quot;0&quot;,&quot;17&quot;,&quot;19&quot;)))
  </code></pre>
  </li>
  </ul>
  <p>This produces:</p>
  <p><img src="https://i.stack.imgur.com/BZy8um.png" alt="enter image description here" /></p>
  <p>So, the colorbar seems correct but the colors are not actually applied.</p>
  <ul>
  <li><p>The solutions given in <a href="https://stackoverflow.com/q/10981324/1081936">ggplot2 heatmap with colors for ranged values</a> seem promising but I can't get them to work with <code>geom_point()</code>.</p>
  </li>
  <li><p>Same goes for various similar posts such as those listed in the sidebar.</p>
  </li>
  </ul>
  <p>I realize I will probably need to use some kind of discrete scale instead of <code>scale_fill_gradientn</code> but my attempts to use <code>scale_color_manual()</code> fail:</p>
  <pre><code>ggplot(mtcars, aes(wt, mpg)) + geom_point(aes(color = factor(qsec))) + 
  scale_color_manual(values=c(&quot;black&quot;, &quot;yellow&quot;,&quot;red&quot;)
  Error: Insufficient values in manual scale. 30 needed but only 4 provided.
  </code></pre>
  <p>I am guessing I will somehow have to use <code>cut()</code> or <code>factor()</code> but I can't seem to figure out how. Any suggestions?</p>