r - Plot time series graph based on readings taken every half hour -
i trying plot time series graph based on data looks following. data contains values recorded every 30 minutes entire day. example data logged 3 hours data frame looks this:
the column names time values shown in half-hours
00:00, 00:30, 01:00, 01:30, 02:00, 02:30, 03:00, 03:30, 04:00, 04:30, 05:00
and respective data values this
0.2, 0.4, 0.3, 0.6, 0.7, 0.6, 0.8, 0.10, 0.2, 0.5, 0.7
the data frame has many rows of data values given respective time columns. need plot time series graph based on these values @ given time. able plot time series have problems depicting x-axis (time value)
imagine a
vector taken row of data frame, then:
a<-c(0.2, 0.4, 0.3, 0.6, 0.7, 0.6, 0.8, 0.10, 0.2, 0.5, 0.7) a.ts <- ts(a, start=0, frequency=24) plot(a.ts)
i getting time series graph below, need have respective hour values (i.e, 00:00, 00:30, , on..) in x-axis instead of start = 0 , on.
i've read documentation ts()
allows specify year , month start values. need hour start value (00:00) in graph goes on till 05:00. i'm stuck on how achieve this. glad if can help!
you'll want have times characters:
time <- c("00:00", "00:30", "01:00", "01:30", "02:00", "02:30", "03:00", "03:30", "04:00", "04:30", "05:00") value <- c(0.2, 0.4, 0.3, 0.6, 0.7, 0.6, 0.8, 0.10, 0.2, 0.5, 0.7)
...and use strptime()
command convert them objects of class "posixlt" (times , dates):
hour.time <- strptime(time, "%h:%m")
finally, plot result.
plot(hour.time, value, type="l")
Comments
Post a Comment