title: Plotting Noncontinuous Function ggplot2
body: <p>I am attempting to plot this function over the values 0 - 1:</p>
  
  <pre><code>dweird &lt;- function(x){
    if (x&lt; 0){return(0)}
    if (x&gt; 1){return(0)}
    if (x &gt;= 0 &amp; x &lt; (1/3)) {return((1))}
    if (x &gt;= (1/3) &amp; x &lt; (2/3)){return(3/2)}
    if (x &gt;= (2/3) &amp; x &lt;= 1){return((1/2))}
  }
  </code></pre>
  
  <p>and here is the code that I'm using </p>
  
  <pre><code>library(ggplot2)
  ggplot(data.frame(x=c(0, 1)), aes(x)) + 
    stat_function(fun=function(x) dweird(x), linetype="dotted")
  </code></pre>
  
  <p>But this returns the error message </p>
  
  <p>Warning message:
  In if (x >= 0 &amp; x &lt; (1/3)) { :
    the condition has length > 1 and only the first element will be used</p>
  
  <p>To be clear, the function should plot one straight line at y= 1 from 0-1/3, another at y=1.5 from 1/3-2/3, and another line at 1/2 from 2/3 to 1. </p>
  
  <p>Any ideas why I'm getting that error message? </p>