title: R - ggplot2 - How to use limits on POSIX axis?
body: <p>What is the smartest way to manipulate POSIX for use in ggplot axis? </p>
  
  <p>I am trying to create a function for plotting many graphs (One per day) spanning a period of weeks, using POSIX time for the x axis. </p>
  
  <p>To do so, I create an additional <strong>integer column</strong> <code>DF$Day</code> with the day, that I input into the function. Then, I create a subset using that day, which I plot using ggplot2. I figured how to use <code>scale_x_datetime</code> to format the POSIX x axis. Basically, I have it show the hours &amp; minutes only, omitting the date. </p>
  
  <p>Here is my question: <em>How can I set the limits for each individual graph in hours of the day?</em></p>
  
  <p>Below is some working, reproducible code to get an idea. It creates the first day, shows it for 3 seconds &amp; the proceeds to create the second day. But, each days limits is chosen based on the range of the <code>time</code> variable. How can I make the range, for instance, all day long (0h - 24h)? </p>
  
  <pre><code>DF &lt;- data.frame(matrix(ncol = 0, nrow = 4))
  
  DF$time &lt;- as.POSIXct(c("2010-01-01 02:01:00", "2010-01-01 18:10:00", "2010-01-02 04:20:00", "2010-01-02 13:30:00"))
  DF$observation &lt;- c(1,2,1,2)
  DF$Day &lt;- c(1,1,2,2)
  
  for (Individual_Day in 1:2) { 
  Day_subset &lt;- DF[DF$Day == as.integer(Individual_Day),]
  
  print(ggplot( data=Day_subset, aes_string( x="time", y="observation") ) + geom_point() +
        scale_x_datetime( breaks=("2 hour"), minor_breaks=("1 hour"), labels=date_format("%H:%M")))
  
  Sys.sleep(3) }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/Za5lp.jpg" alt="Second plot created by the function, to show the axis"></p>