title: Setting x-axis limits for datetime in ggplot
body: <p>I want to plot occupancy rates for a particular parking garage on a particular day in a line chart making use of ggplot.</p>
  
  <p>My dataframe looks as follows:</p>
  
  <pre><code>head(ParkingSub4)
      FreeSpaceShort ShortCapacity            DateTime OccupancyRateShort       Date  Weekday WeekNumber  Week
  310801            257           373 2017-02-25 00:04:41          0.3109920 2017-02-25 Saturday         08 FALSE
  310843            260           373 2017-02-25 00:09:41          0.3029491 2017-02-25 Saturday         08 FALSE
  310885            261           373 2017-02-25 00:14:41          0.3002681 2017-02-25 Saturday         08 FALSE
  310927            260           373 2017-02-25 00:19:41          0.3029491 2017-02-25 Saturday         08 FALSE
  310969            260           373 2017-02-25 00:24:41          0.3029491 2017-02-25 Saturday         08 FALSE
  311011            263           373 2017-02-25 00:29:41          0.2949062 2017-02-25 Saturday         08 FALSE
  
  class(ParkingSub4$DateTime)
  [1] "POSIXlt" "POSIXt" 
  </code></pre>
  
  <p>When I try to plot an overview of a particular day, let's say 23rd of February, 2017 I use the following code:</p>
  
  <pre><code>ggplot(data = ParkingSub4, 
         aes(x=DateTime, y=OccupancyRateShort)) + geom_line(size = 1.25) + facet_wrap(~Weekday) +
        scale_x_datetime(labels=date_format("%H:%m"), breaks = date_breaks("2 hours")) +
        theme_linedraw()
  </code></pre>
  
  <p>Then what I get is the following plot:</p>
  
  <p><a href="https://i.stack.imgur.com/xwRpB.png" rel="noreferrer"><img src="https://i.stack.imgur.com/xwRpB.png" alt="enter image description here"></a></p>
  
  <p>As you can see, the plot starts and ends at 23:02. I want the plot to start at 00:00:00 and end at 23:59:59 on that particular day. How can I do that?</p>
  
  <p>Many thanks in advance!</p>
  
  <p>EDIT/UPDATE:
  Adding the following does lead to the x-axis starting and ending with 00:00:</p>
  
  <pre><code>ggplot(data = ParkingSub4, 
     aes(x=DateTime, y=OccupancyRateShort)) + geom_line(size = 1.25) + facet_wrap(~Weekday) +
    scale_x_datetime(labels=date_format("%H:%m"), breaks = date_breaks("2 hours"), expand=c(0,0)) +
    xlim(c(as.POSIXct('2017-02-23 00:00:00', format = "%Y-%m-%d %H:%M:%S"),
       as.POSIXct('2017-02-24 00:00:00', format = "%Y-%m-%d %H:%M:%S"))) +
    theme_linedraw()
  </code></pre>
  
  <p>Only thing is I get the following message after executing: 'Scale for 'x' is already present. Adding another scale for 'x', which will replace the existing scale.'</p>
  
  <p>This means that <code>scale_x_datetime(labels=date_format("%H:%m"), breaks = date_breaks("2 hours")</code> is overwritten by:
  <code>xlim(c(as.POSIXct('2017-02-23 00:00:00', format = "%Y-%m-%d %H:%M:%S"), as.POSIXct('2017-02-24 00:00:00', format = "%Y-%m-%d %H:%M:%S"))</code>. </p>
  
  <p>That's also not what I want, as now the breaks are set at 6 hours instead of 2 hours, and I can also not specify what information ("%H:%m") is set on the labels.</p>