[R] plotting multiple animal tracks against Date/Time
Gabor Grothendieck
ggrothendieck at gmail.com
Thu Sep 23 19:26:19 CEST 2010
On Thu, Sep 23, 2010 at 9:50 AM, Struve, Juliane
<j.struve at imperial.ac.uk> wrote:
> Dear list,
>
> I would like to create a time series plot in which the paths of several individuals are stacked above each other, with the x-axis being the total observation period of three years ( 1.1.2004 to 31.12.2007) and the y-axis being some defined range[min,max].
>
> My data consist of Date/Time information and the paths of 45 individual as the distance from the location of release. An example data set for 2 individuals is given below.The observation period and frequency of observations varies between individuals.
>
> I believe stackplot() may be able to do this task, but I am not sure how to handle the variable time period and frequency of observations for different individuals. Could someone advise if stackplot() is suitable or if there is a better approach or package ?
>
> Thank you very much for your time and best wishes,
>
> Juliane
>
>
Try this:
Lines1 <- "Date Distance [m]
2006-08-18 22:05:15 1815.798
2006-08-18 22:06:35 1815.798
2006-08-18 22:08:33 1815.798
2006-08-18 22:09:49 1815.798
2006-08-18 22:12:50 1815.798
2006-08-18 22:16:26 1815.798"
Lines2 <- "Date Distance [m]
2006-08-18 09:53:20 0.0
2006-08-18 09:59:07 0.0
2006-08-18 10:09:20 0.0
2006-08-18 10:21:14 0.0
2006-08-18 10:34:18 0.0
2006-08-18 10:36:44 100.2"
library(chron)
dt <- function(date, time) as.chron(paste(date, time))
library(zoo)
library(chron)
# read in data
dt <- function(date, time) as.chron(paste(date, time))
z1 <- read.zoo(textConnection(Lines1), skip = 1, index = list(1, 2), FUN = dt)
z2 <- read.zoo(textConnection(Lines2), skip = 1, index = list(1, 2), FUN = dt)
# create single zoo object
z <- na.approx(cbind(z1, z2), na.rm = FALSE)
# plot -- remove screen=1 if you want separate panels
plot(z, screen = 1)
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-help
mailing list