title: How to plot POSIXct objects / timestamps independent of day?
body: <p>I hope the question title makes sense. I am collecting some data using a Google Form. The form is always submitted between 5 and 7 pm but on different days. I want to plot the <code>time</code> component of the timestamp on the x-axis versus some other value from the form. I want to make sure that all time plots end up in the same two-hour window in the plot (i.e., between 5 and 7pm) regardless of the <code>date</code> component of the timestamp.</p>
  
  <p>I have downloaded the responses as a CSV and can read in the timestamps without any issues:</p>
  
  <p><code>demo &lt;- as.POSIXct(demo$Timestamp, format="%m/%d/%Y %H:%M:%S")</code></p>
  
  <p>And the data looks like this:</p>
  
  <pre><code>&gt; demo
   [1] "2015-10-12 17:02:42 CEST" "2015-10-12 17:02:46 CEST" "2015-10-12 17:02:46 CEST"
   [4] "2015-10-12 17:02:50 CEST" "2015-10-12 17:02:52 CEST" "2015-10-12 17:02:55 CEST"
   [7] "2015-10-12 17:02:58 CEST" "2015-10-12 17:03:02 CEST" "2015-10-12 17:03:09 CEST"
  [10] "2015-10-12 17:03:15 CEST" "2015-10-12 17:03:22 CEST" "2015-10-12 17:03:24 CEST"
  [13] "2015-10-12 17:03:36 CEST" "2015-10-12 17:03:48 CEST" "2015-10-12 17:04:07 CEST"
  [16] "2015-10-12 17:09:20 CEST"
  </code></pre>
  
  <p>I can plot these using something as simple as this:</p>
  
  <pre><code>plot(demo, rnorm(length(demo)))
  </code></pre>
  
  <p>But I want the range on the x-axis to be 5-7pm and I need to make sure that all data is plotted in that two-hour range, independent on the day the data was recorded at. If I do something like this:</p>
  
  <pre><code>startTime &lt;- as.POSIXct("17:00:00", format="%H:%M:%S")
  endTime &lt;- as.POSIXct("19:00:00", format="%H:%M:%S")
  plot(demo, rnorm(length(demo)), xlim=c(startTime, endTime), xaxt='n')
  axis.POSIXct(1, at = seq(startTime, endTime, by="hour"), format = "%M", labels=c("17:00", "18:00", "19:00"))
  </code></pre>
  
  <p>I get the right outline for the plot but no data. This is because <code>startTime</code> and <code>endTime</code> will be set to the current date. If I explicitly use make them the same date as the data in <code>demo</code> ...</p>
  
  <pre><code>startTime &lt;- as.POSIXct("10/12/2015 17:00:00", format="%m/%d/%Y %H:%M:%S")
  endTime &lt;- as.POSIXct("10/12/2015 19:00:00", format="%m/%d/%Y %H:%M:%S")
  </code></pre>
  
  <p>... the data shows up in the plot exactly the way I want them to.</p>
  
  <p><strong>However: I can't add data points from any other day.</strong> Can someone explain to me how I can manipulate/use POSIXct objects to strip them of their "date" component and plot them in the same plot?</p>
  
  <hr>
  
  <p>For testing purposes, you can copy this vector to reproduce the code I posted above:</p>
  
  <pre><code>demo &lt;- as.POSIXct(c("2015-10-12 17:02:42 CEST", "2015-10-12 17:02:46 CEST", "2015-10-12 17:02:46 CEST", "2015-10-12 17:02:50 CEST", "2015-10-12 17:02:52 CEST", "2015-10-12 17:02:55 CEST", "2015-10-12 17:02:58 CEST", "2015-10-12 17:03:02 CEST", "2015-10-12 17:03:09 CEST", "2015-10-12 17:03:15 CEST", "2015-10-12 17:03:22 CEST", "2015-10-12 17:03:24 CEST", "2015-10-12 17:03:36 CEST", "2015-10-12 17:03:48 CEST", "2015-10-12 17:04:07 CEST", "2015-10-12 17:09:20 CEST"))
  </code></pre>