library(knitr) opts_chunk$set(out.extra='style="display:block; margin: auto"', fig.align="center")
Load package library
library(lubridate) library(animalmove) library(plyr) library(ggplot2)
Buffalo dataset has been saved in the package data directory , and loaded on the package load.
Raw buffalo dataset contains unaltered original data.
data(buffalo) head(buffalo) nrow(buffalo) currentnames <- colnames(buffalo) currentnames names(buffalo)[names(buffalo)=="timestamp"] <- "time" names(buffalo)[names(buffalo)=="utm.easting"] <- "x" names(buffalo)[names(buffalo)=="utm.northing"] <- "y" names(buffalo)[names(buffalo)=="tag.local.identifier"] <- "id" names(buffalo)[names(buffalo)=="individual.taxon.canonical.name"] <- "pop.type" # Data Conversion buffalo$time <- as.POSIXct(strptime(buffalo$time,format="%Y-%m-%d %H:%M",tz="GMT")) #Display new names newnames <- colnames(buffalo) newnames head(buffalo)
Number of rows in the buffalo data & data set structure
length(table((buffalo$id))) str(buffalo)
We select at most 6 individuals within 2009, time interval 50 hours, and accuracy 50 hours, and subsampling scheme for Realized Mobility Index
mci.subsample.data <- subsample(dat=buffalo, start=c("2005-02-17 00:00:00"),end="2006-12-31 00:00:00",interval=c("50 hours"),accuracy=c("3 hours"),minIndiv=3,maxIndiv=6,mustIndiv=NULL,index.type="mci") buffalo.indiv <- Individuals(mci.subsample.data, id="id", time="time", x="x", y="y", group.by="pop.type", proj4string= CRS("+proj=utm +zone=28 +datum=WGS84"))
mci.buffalo <- mci.index(buffalo.indiv, group.by = c("pop.type"), time.lag = c("time.lag")) mci.buffalomci.buffalo <- mci.index(buffalo.indiv, group.by = c("pop.type"), time.lag = c("time.lag")) mci.buffalo cexValue = 2 boxplot(mci.index ~ factor(pop.type), data = mci.buffalo, col= "green", border = NULL, outline = F, lwd=2, boxwex = .5, cex = cexValue, cex.lab = cexValue, cex.axis= cexValue, frame = F, ylab = "Movement coordination index", xlab = NULL)
if (length(unique(buffalo.indiv$pop.type)) >1) { anova.model <- aov.mci(mci.buffalo) anova.model }
if (length(unique(buffalo.indiv$pop.type)) >1){ TukeyHSD(anova.model) TukeyHSD(mci.buffalo) }
if (length(unique(buffalo.indiv$pop.type)) >1){ kruskal.test(mci.buffalo) kruskalmc(mci.buffalo) }
if (length(unique(buffalo.indiv$pop.type)) >1){ summary(mci.buffalo) }
library(RColorBrewer) g = 11 my.cols <- rev(brewer.pal(g, "RdYlBu"))
require(KernSmooth) smoothScatter(mci.subsample.data$location.long, mci.subsample.data$location.lat, nrpoints=.3*100000, colramp=colorRampPalette(my.cols), pch=19, cex=.3, col = "green1")
library(MASS) z <- kde2d(mci.subsample.data$location.long, mci.subsample.data$location.lat, n=50) plot(mci.subsample.data$location.long, mci.subsample.data$location.lat, xlab="X", ylab="Y", pch=19, cex=.3, col = "gray60") contour(z, drawlabels=FALSE, nlevels=g, col=my.cols, add=TRUE, lwd = 2) abline(h=mean(mci.subsample.data$location.long), v=mean(mci.subsample.data$location.lat), lwd=2, col = "black") legend("topleft", paste("r=", round(cor(mci.subsample.data$location.long, mci.subsample.data$location.lat),2)), bty="n")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.