[R] Plotting activity by time and dates

Gabor Grothendieck ggrothendieck at gmail.com
Wed Jan 14 04:37:16 CET 2009


Since you have a time series of times this may not be the best application
for zoo.  Read R News 4/1 and try this:

Lines <- "Spec_code       Date    Time
Eptfus          6/4/03  22:44
Eptfus          6/4/03  22:44
Eptfus          6/9/03  21:59
Eptfus          6/10/03 3:24
Eptfus          6/13/03 0:22
Eptfus          6/13/03 3:24
Eptfus          6/17/03 0:03
Eptfus          6/17/03 2:43
Eptfus          6/17/03 21:59"

library(chron)
DF <- read.table(textConnection(Lines), header = TRUE, as.is = TRUE)
DF$Date <- chron(DF$Date)
DF$Time <- times(paste(DF$Time, 0, sep = ":"))
plot(DF$Date, DF$Time)

Lines2 <- "Date   Rise    Set
6/1/2003        4:12    19:50
6/2/2003        4:11    19:51
6/3/2003        4:10    19:52
6/4/2003        4:10    19:53
6/5/2003        4:09    19:54
6/6/2003        4:09    19:54
6/7/2003        4:09    19:55
6/8/2003        4:08    19:56
6/9/2003        4:08    19:57
6/10/2003       4:08    19:57
6/11/2003       4:07    19:58
6/12/2003       4:07    19:58
6/13/2003       4:07    19:59
6/14/2003       4:07    19:59
6/15/2003       4:07    20:00
6/16/2003       4:07    20:00
6/17/2003       4:07    20:01
6/18/2003       4:07    20:01"

SS <- read.table(textConnection(Lines2), header = TRUE, as.is = TRUE)
SS$Date <- chron(SS$Date)
SS$Rise <- times(paste(SS$Rise, 0, sep = ":"))
lines(SS$Date, SS$Rise)
SS$Set <- times(paste(SS$Set, 0, sep = ":"))
lines(SS$Date, SS$Set)




On Tue, Jan 13, 2009 at 10:19 PM, Neotropical bat risk assessments
<neotropical.bats at gmail.com> wrote:
> Hi all,
>
> As I understand the zoo package will aggregate dates and times, but unclear
> how to tackle this problem.
>
> I need to accomplish the following:
>
> 1. Generate a scatter plot of bat activity with dates on the X-axis and time
> on the Y-axis.
> include sunset and sunrise curves as an added part of graphic.
>
> In Excel I have a kludged way to do this, but it is not exactly what I need
> and the times on the Y axis do not display correctly due to the 24:00 roll
> over to next date and would prefer to understand how to do this using R so I
> can repeat it with multiple data sets for multiple locations.
> I removed the Graphic display as apparently the server refused the massage
> with it.
> I can email directly if anyone is able to assist or wished to see it.
>
> A sample of the data format is below.
> Any suggestion welcome.
>
> Tnx.
>
> The bat activity data is in the format below with the species name, date and
> time the species was active.
>
> Spec_code       Date    Time
> Eptfus          6/4/03  22:44
> Eptfus          6/4/03  22:44
> Eptfus          6/9/03  21:59
> Eptfus          6/10/03 3:24
> Eptfus          6/13/03 0:22
> Eptfus          6/13/03 3:24
> Eptfus          6/17/03 0:03
> Eptfus          6/17/03 2:43
> Eptfus          6/17/03 21:59
>
>
>
> The sunset-Sunrise data seen below is also straight forward:
>  Date   Rise    Set
> 6/1/2003        4:12    19:50
> 6/2/2003        4:11    19:51
> 6/3/2003        4:10    19:52
> 6/4/2003        4:10    19:53
> 6/5/2003        4:09    19:54
> 6/6/2003        4:09    19:54
> 6/7/2003        4:09    19:55
> 6/8/2003        4:08    19:56
> 6/9/2003        4:08    19:57
> 6/10/2003       4:08    19:57
> 6/11/2003       4:07    19:58
> 6/12/2003       4:07    19:58
> 6/13/2003       4:07    19:59
> 6/14/2003       4:07    19:59
> 6/15/2003       4:07    20:00
> 6/16/2003       4:07    20:00
> 6/17/2003       4:07    20:01
> 6/18/2003       4:07    20:01
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list