Hi

 

If you want to track the individual fish try turning the graph around. not
all is displayed - just a concept graph

 

windows(10,8)

xyplot(gspd_mps ~ as.POSIXct(x)|TagID, dat,

       as.table = TRUE,

       layout = c(1,14),

       groups = Station,

       strip = FALSE,

       type = c("p","g"),

       par.settings = list(strip.background = list(col = "transparent"),

                           superpose.symbol = list(cex = c(1,0.7),

                                                   col = c(1:7),

                                                   pch = c(20,1:13))),

       strip.left = strip.custom(par.strip.text = list(cex = 0.65) ),

       scales = list(x = list(alternating = FALSE,

                              rot = 90)),

       auto.key = list(points = TRUE, lines = F, rectangles = F, columns =
8)

       )

 

with more fish you can have more columns in the layout argument eg c(5,14)
which cuts down the graphs

 

Duncan

 

From: Natalie Houghton McNair [mailto:nhoughton01@gmail.com] 
Sent: Wednesday, 27 November 2013 00:29
To: Duncan Mackay
Subject: Re: [R] Plotting multiple trends on one graph

 

Thank you!!  This is a great graph!  I hadn't envisioned one like this, but
it's very effective at displaying what I want to see.  It works better with
a small number of individuals and I have hundreds, but I think I will use
this to display trends of some of the interesting outliers or identify
predation (I'm tracking juvenile fish).

 

Thanks again, I really appreciate your help!

Natalie

 

On Sun, Nov 24, 2013 at 4:05 PM, Duncan Mackay <dulcalma@bigpond.com> wrote:

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@northnet.com.au


-----Original Message-----
From: r-help-bounces@r-project.org [mailto:r-help-bounces@r-project.org] On
Behalf Of Natalie Houghton McNair
Sent: Monday, 25 November 2013 02:49
To: R-help@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.
>

Thanks for the help!!  I'm very new to R.
Natalie

   TagID Station datetime gspd_mps  4926 KLB 12/21/2012 1:52 NA  4926
MS01 12/21/2012
2:38 0.851 4926 <tel:38%200.851%20%204926>  MS02 12/21/2012 3:48 0.629 4926
<tel:48%200.629%20%204926>  MS03 12/21/2012 4:19 0.86
4926 MS04 12/21/2012 4:34 1.131  4926 MS05 12/21/2012 5:01 0.9  4926
MS06 12/21/2012
6:54 0.798  4926 MS07 12/21/2012 7:21 0.853  4926 MS08 12/21/2012 10:23
0.694  4926 MS09 12/21/2012 12:16 0.6  4926 MS10 12/21/2012 14:38 0.647
4929 KLB 12/21/2012 1:08 NA  4929 MS01 12/21/2012 2:12 0.611  4929
MS02 12/21/2012
3:33 0.563  4929 MS03 12/21/2012 3:59 1.04  4929 MS04 12/21/2012 4:13 1.082
4929 MS05 12/21/2012 5:00 0.475  4929 MS06 12/21/2012 6:52 0.796  4929
MS07 12/21/2012
7:32 0.563  4929 MS08 12/21/2012 10:16 0.809  4929 MS09 12/21/2012 11:43
0.783  4929 MS10 12/21/2012 14:02 0.657  4929 MS11 12/22/2012 2:50 0.326
4929 MS12 12/22/2012 5:04 0.709  4929 MS13 12/22/2012 13:59 0.688
>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

 


	[[alternative HTML version deleted]]

