plotting issue with timestamps
On 8/17/05, Dhiren DSouza <dhiren22 at hotmail.com> wrote:
I have a dataset with transactions and a timestamp at which they occoured during a day. The time stamp is in the format YYYY/MM/DD hh:mm:ss. I would like to plot a timeseries of the transactions to see if there is a particular time in the day when there is a spike in transactions. Ofcourse the YYYY/MM/DD can be dropped since I am monitoring activity for the day and the actual date is unimportant. Can anyone give me some direction on this. I could possibly build a frequency table but not sure how to plot against the timestamp in the format above. Any help would be appreciated.
Lets say your times are in a character vector tt. (If the dates
are there too use substring to remove them.) Then convert them
to times class (of library chron) which will represent them
internally as a fraction of a day where the day starts at 0 and
goes to 1 so that 0.5 is noon. Since we want a more meaningful
axis do not use the automatic plot axis (xaxt = "n") and also
restrict the xaxis to the internval 0:1. So that we can get
all the hours to fix reduce the size of the axis labels to 70%.
Then redraw it yourself with the hours labelled and add some
light grey vertical lines if you like.
library(chron)
tt <- c("10:11:12", "09:10:11", "01:02:03")
tt.times <- times(tt)
plot(density(tt.times), xaxt = "n", xlim = 0:1, xlab = "Hour")
axis(1, 0:24/24, 0:24, cex.axis = 0.7)
abline(v = 0:24/24, col = "lightgrey")
See RNews 4/1 Help Desk article for more.