[R] Plotting times at night and getting plot limits correct

Bob O'Hara rni.boh at gmail.com
Tue May 12 16:34:47 CEST 2015


I'm helping colleagues with analysis of frog calls at night, and they
want to plot call statistics against time. This means we hit a
problem: we want the x-axis to start at (say) 18:00 and end at (say)
06:00. I'm reluctant to use the date as well, because we have data
from several dates, but only want to plot against time of day.

Here's some code to illustrate the problem (don't worry about the data
being outside the range of the plot: this is only for illustration).

library(chron)
Times <- chron(times.=paste(c(18:23,0:9),":30:00", sep=""))
Thing <- rnorm(length(Times)) # just something for the y-axis

plot(Times,Thing) # x-axis wrong
plot(Times,Thing, xlim=chron(times.=c("05:00:00", "18:00:00"))) # x-axis right
plot(Times,Thing, xlim=chron(times.=c("18:00:00", "05:00:00"))) #
would like this to work...

Can anyone suggest a solution?

Bob

-- 
Bob O'Hara

Biodiversity and Climate Research Centre
Senckenberganlage 25
D-60325 Frankfurt am Main,
Germany

Tel: +49 69 798 40226
Mobile: +49 1515 888 5440
WWW:   http://www.bik-f.de/root/index.php?page_id=219
Blog: http://occamstypewriter.org/boboh/
Journal of Negative Results - EEB: www.jnr-eeb.org



More information about the R-help mailing list