title: X-axis for times
body: <p>I am trying to generate a series of plots that show the same patient taking drinks and urinating at different times.  Each plot represents a single day.  I want to compare the days and hence I need to ensure that all graphs plotted have the same x-axis.  My code is below which I cribbed from <a href="https://stackoverflow.com/questions/11775692/how-to-specify-the-actual-x-axis-values-to-plot-as-x-axis-ticks-in-r">How to specify the actual x axis values to plot as x axis ticks in R</a></p>
  
  <pre><code>### Data Input
  
  time_Thurs &lt;- c("01:10", "05:50", "06:00","06:15", "06:25", "09:35", "10:00", "12:40",
                "14:00", "17:20", "18:50", "19:10", "20:10", "21:00", "22:05", "22:35")
  event_Thurs &lt;- c("u", "u", "T", "T", "u", "u", "T","T","u", "u", "T", "T", "T", "T", "u", "W")
  volume_Thurs &lt;- c(NA, NA, 0.25, 0.25, NA, NA, 0.125, 0.625, NA, NA, 0.25, 0.25, 0.25, 0.25,
              NA, 0.25)
  total_liquids_Thurs &lt;- sum(volume_Thurs, na.rm=TRUE)
  time_Thurs &lt;- paste("04/04/2019", time_Thurs, sep=" ")
  
  time_Fri &lt;- c("01:15", "06:00", "06:10", "06:25", "06:30", "07:10", "08:40", "09:20",
                "12:45", "13:45")
  event_Fri &lt;- c("u","u", "T","T","u","uu","T", "u", "T", "u")
  volume_Fri &lt;- c(NA, NA, 0.25, 0.25, NA, NA, 0.125, NA, 0.625, NA)
  total_liquids_Fri &lt;- sum(volume_Fri, na.rm=TRUE)
  time_Fri &lt;- paste("05/04/2019", time_Fri, sep=" ")
  
  ### Collect all data together
  
  event &lt;- c(event_Thurs, event_Fri)
  Volume &lt;- c(volume_Thurs, volume_Fri)
  time_log &lt;- c(time_Thurs, time_Fri)
  time_log &lt;- strptime(time_log, format = "%d/%m/%Y %H:%M")
  time_view &lt;- format(time_log, "%H:%M")
  
  ### Put into Dataframe
  
  patient_data &lt;- data.frame(time_log, time_view, event, Volume)
  
  # write.csv(patient_data, file="patient_data.csv", row.names = FALSE)
  
  daily_plot &lt;- function(x, day) {
    #    x patient data - a data.frame with four columns:
    #    POSIXct time, time, event and Volume
    #    date number of day of month
    #    y volume of liquid
    #    TotVol total volume of intake over week
    #    Event - drink or otherwise
  
    x &lt;- x[as.numeric(format(x[,1], "%d")) == day, ]
    TotVol &lt;- sum(x[,4], na.rm = TRUE)
    DayOfWeek &lt;- weekdays(x[1,1], abbreviate = FALSE)
  
    plot(x[,1],x[,4], 
         xlim = c(x[1,1],x[length(x[,1]),1]),
         xlab="Hours of Study", ylab = "Volume of Liquid Drank /L",
         main = paste("Total Liquids Drank = ", TotVol, " L on ", DayOfWeek, "Week 1, Apr 2019"),
         sub = "dashed red line = urination", pch=16,
         col = c("black", "yellow", "green", "blue")[as.numeric(x[,3])],
         xaxt = 'n'
    )
    xAxis_hrs &lt;- seq(as.POSIXct(x[1,1]), as.POSIXct(x[length(x[,1]),1]), by="hour")
    axis(1, at = xAxis_hrs, las = 2)
    abline( v = c(x[x[,3] == "u",1]), lty=3, col="red")
  }
  </code></pre>
  
  <p>When I run the function,</p>
  
  <pre><code>daily_plot(patient_data, 4)
  </code></pre>
  
  <p>I want to print out my x-axis, as amended in the form of hours representing the events over the 24 hour period.</p>
  
  <p>When I wrap my xAxis_hrs vector in strptime(xAxis_hrs, format = "%H") the code crashes - that is the x-axis doesn't print out and I see, Error in axis(1, at = xAxis_hrs, las = 2) : (list) object cannot be coerced to type 'double' .  Any help?</p>