Graph for Activity overlap

421 views
Skip to first unread message

Sally Soo

unread,
Mar 20, 2017, 3:11:13 PM3/20/17
to camtrapR
Hi,

I would like to ask how can I perform more than two species of activity overlap graph?

Thanks for your help in advance :)



Juergen Niedballa

unread,
Mar 21, 2017, 6:16:12 AM3/21/17
to camt...@googlegroups.com
Hi Sally,
currently this is not supported in the package. What you could do for visualisation is use the output of the function activityDensity from camtrapR (which is radial time, or alternatively the function ClocktimeToTimeRad which you find in my respones to the question Customozing activityOverlap plots her in the group) and put that into the densityPlot function from the overlap package for single species. Output will be x and y coordinates of the activity kernel density estimation. These you could then combine into a common plot.

Here's the rough idea:

library(overlap)

list_records_radial_time <- activityDensity(recordTable = recordTableSample,
                allSpecies  = TRUE,
                writePNG    = FALSE,
                plotR       = F)

str(list_records_radial_time)
names(list_records_radial_time)
densities <- lapply(list_records_radial_time, densityPlot)

plot(densities[[1]], type = "l", ylim = c(0, max(sapply(densities, FUN = function(df){df$y}))))   # plot densities of first species in list
lines(densities[[2]], col = "red")
lines(densities[[3]], col = "blue")

Auto Generated Inline Image 1

Sally Soo

unread,
Mar 22, 2017, 12:41:21 PM3/22/17
to camtrapR
Hi, Juergen

I tried with your solution but i have another problem while i tried to run densities <- lapply(list_records_radial_time, densityPlot). it still show me with this error: Error in FUN(X[[i]], ...) : Bandwidth estimation failed.

Can you help me with this?


Regards,

Sally

Juergen Niedballa

unread,
Mar 22, 2017, 1:43:00 PM3/22/17
to camtrapR

Hi Sally,

this is probably because there are species with only one record in your table. Remove these and try again. You could use something like

 

min_number_records <- 2                                                                                               # minimum number of records per species
species_to_keep <- names(table(recordTableSample$Species))[table(recordTableSample$Species) >= min_number_records]    # list all those species
recordTableSample2 <- recordTableSample[recordTableSample$Species %in% species_to_keep,]                              # subset

 

to remove all records with less than 2 records.

 

Hope this helps,

Jürgen

Sally Soo

unread,
Apr 14, 2017, 4:06:10 AM4/14/17
to camtrapR
Hi, Juergen,

If works for me. Thanks for your help :)


Regards,

Sally

Sally Soo

unread,
Jan 8, 2018, 2:57:06 AM1/8/18
to camtrapR
Hi, Juergen,


Happy new yaer!

I have problem with this script, I'm using same data same script but not getting same result. Can you help me with this?

this is the script:

library(camtrapR)

data(recordTableSample)

ClocktimeToTimeRad <- function(Clocktime,
                               timeformat = "%Y-%m-%d %H:%M:%S"){

  DateTime2 <- strptime(as.character(Clocktime), format = timeformat, tz = "UTC")
  Time2     <- format(DateTime2, format = "%H:%M:%S", usetz = FALSE)
  Time.rad  <- (as.numeric(as.POSIXct(strptime(Time2, format = "%H:%M:%S", tz = "UTC"))) -
                  as.numeric(as.POSIXct(strptime("0", format = "%S", tz = "UTC")))) / 3600 * (pi/12)
  return(Time.rad)
}

recordTableSample$TimeRad <- ClocktimeToTimeRad(recordTableSample$DateTimeOriginal)


library(overlap)

list_records_radial_time <- activityDensity(recordTable = recordTableSample,
                allSpecies  = TRUE,
                writePNG    = FALSE,
                plotR       = F)
               

str(list_records_radial_time) ##I have problem here, it only able to detect one species while the other 4 listed as NA.

names(list_records_radial_time)
densities <- lapply(list_records_radial_time, densityPlot)

plot(densities[[1]], type = "l", lwd = 3, ylim = c(0, max(sapply(densities, FUN = function(df){df$y}))))   # plot densities of first species in list
lines(densities[[2]], col = "black", lty = 3, lwd = 3)
lines(densities[[3]], col = "black", lty = 5, lwd = 3)


Thanks for your attention ^^

Juergen Niedballa

unread,
Jan 13, 2018, 12:37:38 PM1/13/18
to camtrapR
Hi Sally, 
thank you, this is a bug in the function activityDensity and arises when argument allSpecies = TRUE. I will fix it in the next release. In the meantime you can use this code instead (changes highlighted in red):


library(camtrapR)

data(recordTableSample)

ClocktimeToTimeRad <- function(Clocktime,
                               timeformat = "%Y-%m-%d %H:%M:%S"){
  
  DateTime2 <- strptime(as.character(Clocktime), format = timeformat, tz = "UTC")
  Time2     <- format(DateTime2, format = "%H:%M:%S", usetz = FALSE)
  Time.rad  <- (as.numeric(as.POSIXct(strptime(Time2, format = "%H:%M:%S", tz = "UTC"))) -
                  as.numeric(as.POSIXct(strptime("0", format = "%S", tz = "UTC")))) / 3600 * (pi/12)
  return(Time.rad)
}

recordTableSample$TimeRad <- ClocktimeToTimeRad(recordTableSample$DateTimeOriginal)


library(overlap)

list_records_radial_time <- activityDensity(recordTable = recordTableSample,
                                            allSpecies  = TRUE,
                                            writePNG    = FALSE,
                                            plotR       = F)

list_records_radial_time <- list()
for(i in 1:length(unique(recordTableSample$Species))){
  list_records_radial_time[[i]] <- activityDensity(recordTable = recordTableSample,
                                                   species = unique(recordTableSample$Species)[i],
                                                   allSpecies  = FALSE,
                                                   writePNG    = FALSE,
                                                   plotR       = F)
  
  
}
names(list_records_radial_time) <- unique(recordTableSample$Species)

Sally Soo

unread,
Jan 17, 2018, 4:28:22 AM1/17/18
to camtrapR
Thank your very much Jeurgen.


Reply all
Reply to author
Forward
0 new messages