[R] Plot time series data irregularly hourly-spaced

Law, Jason Jason.Law at portlandoregon.gov
Thu Oct 17 02:04:21 CEST 2013


 You just need the date, otherwise how would it know what time comes first?  In strptime(), a date is being assumed.

Try this:

testtime<-c("20:00:00","22:10:00","22:20:00","23:15:00","23:43:00","00:00:00","00:51:00","01:00:00")
testday <- rep(Sys.Date() - c(1,0), times = c(5,3))
plot(as.POSIXct(paste(testday, testtime)), var)

Jason

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Charles Novaes de Santana
Sent: Wednesday, October 16, 2013 2:58 PM
To: r-help at r-project.org
Subject: [R] Plot time series data irregularly hourly-spaced

Dear all,

I have a time series of data that I would like to represent in a plot. But I am facing some problems to do it because the time is represented in "hours", it can start in one day and end in another day, and it is not regularly spaced.

My problem is that when I plot my data, my X-axis always starts from the lower values of my time data. For example, I would like to plot data that starts at 20:00:00 and ends at 01:00:00, but R considers that 01:00:00 is lower than 21:00:00 and my plot is kind of "crossed over time".

Please try this example to see it graphically:

testtime<-c("20:00:00","22:10:00","22:20:00","23:15:00","23:43:00","00:00:00","00:51:00","01:00:00")
var<-runif(length(testtime),0,1)
plot(strptime(testtime,format="%H:%M:%S"),var,type="b",xlab="Time",ylab="Var")

In this case, I would like to have a plot that starts at 20:00:00 and ends at 01:00:00.

Does anybody know how to make R understand that 00:00:00 comes after 20:00:00 in this case? Or at least does anybody know a tip to make a plot with this kind of X-axis?

Thanks for your time and thanks in advance for any help.

Best regards,

Charles
--
Um axé! :)

--
Charles Novaes de Santana, PhD
http://www.imedea.uib-csic.es/~charles

	[[alternative HTML version deleted]]



More information about the R-help mailing list