Hi Natalie
Here is an option using lattice. I think below will get you some way to what
you want
This is your data formatted. in future please dput your data as your data
was scrambled.
# dput(dat)
dat <- structure(list(TagID = c(4926L, 4926L, 4926L, 4926L, 4926L, 4926L,
4926L, 4926L, 4926L, 4926L, 4926L, 4929L, 4929L, 4929L, 4929L,
4929L, 4929L, 4929L, 4929L, 4929L, 4929L, 4929L, 4929L, 4929L,
4929L), Station = c("KLB", "MS01", "MS02", "MS03", "MS04", "MS05",
"MS06", "MS07", "MS08", "MS09", "MS10", "KLB", "MS01", "MS02",
"MS03", "MS04", "MS05", "MS06", "MS07", "MS08", "MS09", "MS10",
"MS11", "MS12", "MS13"), datetime = c("12/21/2012 1:52", "12/21/2012 2:38",
"12/21/2012 3:48", "12/21/2012 4:19", "12/21/2012 4:34", "12/21/2012 5:01",
"12/21/2012 6:54", "12/21/2012 7:21", "12/21/2012 10:23", "12/21/2012
12:16",
"12/21/2012 14:38", "12/21/2012 1:08", "12/21/2012 2:12", "12/21/2012 3:33",
"12/21/2012 3:59", "12/21/2012 4:13", "12/21/2012 5:00", "12/21/2012 6:52",
"12/21/2012 7:32", "12/21/2012 10:16", "12/21/2012 11:43", "12/21/2012
14:02",
"12/22/2012 2:50", "12/22/2012 5:04", "12/22/2012 13:59"), gspd_mps = c(NA,
0.851, 0.629, 0.86, 1.131, 0.9, 0.798, 0.853, 0.694, 0.6, 0.647,
NA, 0.611, 0.563, 1.04, 1.082, 0.475, 0.796, 0.563, 0.809, 0.783,
0.657, 0.326, 0.709, 0.688)), .Names = c("TagID", "Station",
"datetime", "gspd_mps"), class = "data.frame", row.names = c(NA,
-25L))
# factor of id
dat[,1] <- factor(dat[,1])
# convert to datetime
x <- paste(dat[,3])
x <- strptime(x, "%m/%d/%Y %H:%M")
I have added a few extra formatting options but I will leave you to format
the x labels as an exercise.
# lattice plot conditioned by station
library(lattice)
xyplot(gspd_mps ~ as.POSIXct(x)|Station, dat,
as.table = TRUE,
layout = c(1,14),
groups = TagID,
strip = FALSE,
type = c("p","g"),
par.settings = list(strip.background = list(col = "transparent"),
superpose.symbol = list(cex = c(1,0.7),
col = c("red","blue"),
pch = c(20,3))),
strip.left = strip.custom(par.strip.text = list(cex = 0.65) ),
scales = list(x = list(alternating = FALSE,
rot = 90)),
auto.key = TRUE
)
# using latticeExtra conditioned by station and tag
library(latticeExtra)
useOuterStrips(strip = strip.custom(factor.levels = paste("TagID",
unique(dat$TagID)),
par.strip.text = list(cex = 0.85)),
strip.left = strip.custom(horizontal = TRUE,
par.strip.text = list(cex = 0.75)),
strip.left.lines = 2,
xyplot(gspd_mps ~ as.POSIXct(x)|TagID*Station, dat,
as.table = TRUE,
scales = list(x = list(alternating = FALSE,
rot = 90)),
type = c("p","g")
)
) ## useOuterStrips
useOuterStrips(strip = strip.custom(factor.levels = paste("TagID",
unique(dat$TagID)),
par.strip.text = list(cex = 0.85)),
strip.left = strip.custom(horizontal = TRUE,
par.strip.text = list(cex = 0.75)),
strip.left.lines = 2,
xyplot(gspd_mps ~ as.POSIXct(x)|TagID*Station, dat,
as.table = TRUE,
scales = list(x = list(alternating = FALSE,
rot = 90)),
panel = function(x,y, ...){
panel.grid(h = 0, v= -1)
panel.xyplot(x,y,...)
}
)
) ## useOuterStrips
HTH
Duncan
Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Natalie Houghton McNair
Sent: Monday, 25 November 2013 02:49
To: R-help at r-project.org
Subject: [R] Plotting multiple trends on one graph
Hello all,
I am tracking hundreds of animals through a system with multiple
timing points. I want to graph the movement of individuals through
the whole array on one graph, but I can't figure out how to do that.
An example of my data is below. Basically for each 'TagID', I want to
graph the 'date'
or 'gspd_mps' on the X axis and 'Station' on the Y axis, with all
TagID's on one graph.