Skip to content
Prev 75750 / 398502 Next

plotting issue with timestamps

On 8/17/05, Dhiren DSouza <dhiren22 at hotmail.com> wrote:
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.