title: Manual breaks of facet_wrap() in ggplot2
body: <p><strong>Problem</strong></p>
  
  <p>I am trying to understand how to provide y-axis breaks manually to facets, generated by the <code>facet_wrap()</code> function in <code>ggplot2</code> in <code>R</code>. </p>
  
  <p><strong>Minimal reproducible example</strong></p>
  
  <p>Disclaimer: I have borrowed the following example from the <a href="https://community.rstudio.com/t/separate-axis-breaks-for-facets/10352/3" rel="nofollow noreferrer">R studio community</a></p>
  
  <p>With the following code, you can specify the y-axis breaks based on the y-axis values in de dataset. </p>
  
  <pre><code>library(ggplot2)
  diamonds2 &lt;- subset(diamonds, !(cut == "Fair" &amp; price &gt; 5000))
  
  my_breaks &lt;- function(x) { if (max(x) &lt; 6000) seq(0, 5000, 1000) else seq(0, 15000, 5000) }
  
  ggplot(data = diamonds2, aes(x = carat, y = price)) +
    facet_wrap(~ cut, scales = "free_y") +
    geom_point() +
    scale_y_continuous(breaks = my_breaks)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Lm0pP.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Lm0pP.jpg" alt="enter image description here"></a></p>
  
  <p><strong>Question</strong></p>
  
  <p>I would like to be able to specify the breaks manually, based on the <code>facet</code> (in this case: based on the 'cut' of the diamonds). For example, I would like to set the breaks for the 'Fair' cut to <code>seq(1000, 2500, 5000)</code>, the breaks for the 'Good' cut to <code>seq(1500, 3000, 4500, 6000, ..., 15000)</code> and the rest to <code>seq(0,15000, 5000)</code>.</p>
  
  <p><strong>Attempt</strong></p>
  
  <p>I thought that adapting the <code>my_breaks</code> function with an if-else-ladder, specifying the 'cut' would solve the problem, however, it doesn't:</p>
  
  <pre><code>my_breaks &lt;- function(x) { 
    if (cut == "Fair") {seq(0, 5000, 1000) }
    else if (cut == "Good") {seq(1500,15000, 1500)}
    else { seq(0, 15000, 5000) }
  }
  </code></pre>
  
  <p>It provides the error: </p>
  
  <blockquote>
    <p>Error in cut == "Fair" :    comparison (1) is possible only for atomic
    and list types</p>
  </blockquote>
  
  <p>Is there another approach to manually provide the breaks to different facets?</p>