[R] Line plot with date-time on X-axis
Michael A. Miller
mmiller3 at iupui.edu
Mon Nov 4 16:37:54 CET 2002
>>>>> "Malladi," == Malladi, Sukhaswami <smalladi at lexgen.com> writes:
> Dear List, What is the way in R to plot a graph having date
> time (e.g. format 12/31/2002 13:12) in the x axis and
> numerical value (e.g. temperature) on the Y-axis ?
I tend to use chron for that sort of thing.
Mike
> df
date time temp
1 2002/08/09 12:15:00 98
2 2002/08/09 13:15:00 95
3 2002/08/09 14:15:00 94
4 2002/08/08 15:15:00 90
5 2002/08/08 16:15:00 88
6 2002/08/08 17:15:00 80
7 2002/08/08 18:15:00 71
8 2002/08/08 19:15:00 76
> library(chron)
> df$datetime <- chron(dates=as.character(df$date),
times=df$time,format=c('y/m/d', 'h:m:s')) # date and time
> df$dates <- dates(df$datetime) # just the dates, with no time
> df$times <- times(df$time) # just the times, independent of date
>
> df
date time temp datetime dates times
1 2002/08/09 12:15:00 98 (02/08/09 12:15:00) 08/09/02 12:15:00
2 2002/08/09 13:15:00 95 (02/08/09 13:15:00) 08/09/02 13:15:00
3 2002/08/09 14:15:00 94 (02/08/09 14:15:00) 08/09/02 14:15:00
4 2002/08/08 15:15:00 90 (02/08/08 15:15:00) 08/08/02 15:15:00
5 2002/08/08 16:15:00 88 (02/08/08 16:15:00) 08/08/02 16:15:00
6 2002/08/08 17:15:00 80 (02/08/08 17:15:00) 08/08/02 17:15:00
7 2002/08/08 18:15:00 71 (02/08/08 18:15:00) 08/08/02 18:15:00
8 2002/08/08 19:15:00 76 (02/08/08 19:15:00) 08/08/02 19:15:00
>
> plot(temp ~ date, data=df)
> plot(temp ~ time, data=df)
> plot(temp ~ datetime, data=df)
> plot(temp ~ dates, data=df)
> plot(temp ~ times, data=df)
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list