Skip to content
Prev 332960 / 398503 Next

Show time in x-axis

On 11/11/2013 09:07 PM, mohan.radhakrishnan at polarisft.com wrote:
Hi Mohan,
Yes, you probably want to convert the "Time" variable. However, to 
answer both questions in one, you also probably want to stick a starting 
date on your times, incrementing this whenever a time is less than the 
previous one:

# this will produce times for the current date
data$Time1<-strptime(data$Time,"%H:%M:%S")
offset<-0
lasttime<-0
for(timedate in 1:length(data$Time1)) {
  if(as.numeric(data$Time1[timedate]) < lasttime) offset<-offset + 86400
  data$Time1[timedate]<-data$Time1[timedate]+offset
  lasttime<-data$Time1[timedate]
}

Then you can use "Time1" as the "at" argument, and "Time" as the 
"labels" argument to axis.

Jim