title: R ggplot2 - setting breaks when also using facets
body: <p>I want to have some more flexibility for setting the breaks on a <code>ggplot</code> that has facets.</p>
  <pre><code>library(data.table)
  library(tidyverse)
  dt &lt;- data.table(x = rnorm(1000),
                   group = sample(c(1,2), size=1000, replace = TRUE))
  </code></pre>
  <p>The problem is I want to create the breaks based off all of the data for a particular facet, but the <a href="https://ggplot2.tidyverse.org/reference/scale_continuous.html" rel="nofollow noreferrer">documentation</a> for breaks says:</p>
  <blockquote>
  <p>A function that takes the limits as input and returns breaks as output (e.g., a function returned by scales::extended_breaks()). Also accepts rlang lambda function notation.</p>
  </blockquote>
  <p>Note that you just get the <em>limits</em> of the data for that facet. Say I want to use the output of <code>summary</code> to create my breaks. E.g.:</p>
  <pre><code>breaks_f &lt;- function(x){ 
    print(x) # included this to confirm I only get limits
    as.numeric(ceiling(summary(x)))
  }
  
  dt %&gt;% 
    ggplot(aes(x=x)) +
    geom_density(adjust=.8, color = NA, alpha = .8, fill = 'blue')+
    scale_x_continuous(breaks = breaks_f) +
    facet_wrap(vars(group), scales = 'free')
  </code></pre>
  <p>You'll see if you run this, you'll get breaks that based off taking <code>summary(c(min, max))</code> for each facet, <em>not</em> all of the data for that facet.</p>
  <p>So is there a way to access all of the data within each facet?</p>
  <p>Thanks!</p>