File: all_spaceuse_dataproc.R

Comment:  DOWNSAMPLING  Loop to downsample data based on minimum time and distance between points Time parameter is set in "while(diff < time in minutes | dist > in meters)" downsampled pts that were less than 60min apart unless frog moved more than 20m during the time window 
Category: Data Variable
Code:
tracks_dsmpl <- data.frame() ids <- unique(tracks$id) for(i in ids) { traj = subset(tracks, tracks$id == i) for(i in 1:nrow(traj)) { diff <- difftime(traj$dt[i+1], traj$dt[i], units = "mins") delta_x <- traj$x_utm[i+1] - traj$x_utm[i] delta_y <- traj$y_utm[i+1] - traj$y_utm[i] dist <- sqrt(delta_x^2+delta_y^2) if(is.na(diff)) {break} while(diff <= 60 & dist < 20) { traj <- traj[-(i+1),] diff <- difftime(traj$dt[i+1], traj$dt[i], units = "mins") delta_x <- traj$x_utm[i+1] - traj$x_utm[i] delta_y <- traj$y_utm[i+1] - traj$y_utm[i] dist <- sqrt(delta_x^2+delta_y^2) if(is.na(diff)) {break} } } tracks_dsmpl <- bind_rows(tracks_dsmpl, traj) } tracks_dsmpl <- tracks_dsmpl %>% group_by(id) %>% mutate(time_diff = difftime(dt, lag(dt, n = 1L), units = "min"), delta_x = x_utm - lag(x_utm, n = 1L), delta_y = y_utm - lag(y_utm, n = 1L), dist = sqrt(delta_x^2+delta_y^2)) tracks <- tracks_dsmpl

Comment:  Remove first row (tagging date) and last row (untagging day) per individual   Sort the daily, group by id and add index of id+date as a new variable 
Category: Data Variable
Code:
daily %>% arrange(id) %>% group_by(id) %>% mutate(id_day = paste(id, date)) -> daily_grouped

Comment: Join with summary stats
Category: Visualization
Code:
tracks_sum  <- left_join(tracks_sum, duration) tracks_sum  <- left_join(tracks_sum, relocs) tracks_sum  <- left_join(tracks_sum, days_tracked)

Comment: Calculate average daily movement by behavioral category per individual for plotting
Category: Visualization
Code:
daily_beh_mean <- daily_beh %>% group_by(id, behavior) %>% dplyr::summarize(daily_dist = mean(daily_dist), max_dist = mean(max_dist), sex = first(sex), species = first(species))

Comment: MCPs home range with 95% minimum convex ploygon (MCP95)
Category: Data Variable
Code:
mcp95<- mcp(data_sp["id"], percent = 95, unout = "m2")

Comment: 95% contour with hpi pluging method Define countour level
Category: Visualization
Code:
cont=c(95)

Comment: Initiate empty df to store the metadarta
Category: Data Variable
Code:
allfrogs_info <- data.frame(ID = numeric(0), Cont = numeric(0), frog_id = character(0)) allfrogs_info <- data.frame(ID = numeric(0), Cont = numeric(0), frog_id = character(0))

Comment: BOXPLOTS: DAILY MOVEMENT  FIGURE EXPORT: daily movement by sex
Category: Visualization
Code:
daily_plot <-tracks_sum%>% ggplot(aes(x= sex, y=log(mean_cumul), fill = species)) + theme_bw(20) + geom_boxplot(width= 0.6, outlier.shape = NA) + geom_jitter(aes(group = sex), position=position_jitterdodge(0.4), shape = 21, stroke = 1, color = "black", size = 2, alpha = 0.6) + scale_color_manual(values=c("black", "black")) + scale_fill_manual(values=c("#E7B800", "#0072B2","#FC4E07")) + theme(legend.position="none") + labs(y = "ln Daily movement (m)") + facet_wrap(~species, labeller = labeller(species=c("afemo" = "A. femoralis", "dtinc" = "D. tinctorius", "osylv" = "O. sylvatica"))) + theme(axis.title.x = element_blank(), axis.text.x = element_text(color = "black", size = 18), strip.text = element_text(face = "italic"), aspect.ratio = 4) + scale_x_discrete(labels= c("F", "M"), expand = expansion(add = 1)) daily_plot

Comment: Daily movement by sex and species, log transformed violin plots 
Category: Visualization
Code:
ggplot(daily_select, aes(x= sex, y=log(daily_dist))) + theme_bw(20) + geom_violin(aes(fill = species)) + scale_fill_manual(values=c("#E7B800", "#0072B2","#FC4E07")) + theme(legend.position="none") + labs(y = "ln Daily movement (m)") + geom_jitter(aes(shape=sex, fill = species), position=position_jitterdodge(0.2), size = 4, alpha=0.2) + facet_wrap(~species, labeller = labeller( species=c(afemo ="A. femoralis", dtinc = "D. tinctorius", osylv = "O. sylvatica"))) + theme(axis.title.x = element_blank(), axis.text.x = element_text(color = "black", size = 18), strip.text = element_text(face = "italic")) + scale_x_discrete(labels= c("F", "M"))