Research Question

Q1. Clearly state your research question and describe the spatial analyses you intend to conduct to answer this question.

How do habitat variables interact with comparisons of cougar activity and mule deer, elk, and human activity over the diel cycle?

Based on the literature, relevant variables that may impact cougar-prey interactions include ruggedness, tree cover, and edge habitat variables. I would take the following steps to address how these spatial variables influence species interactions: 1. Create layers for each of the spatial variables based on existing methods in the wildlife literature. 2. Buffer camera-trap point locations with a 250 meter radius. 3. Overlay habitat variables with buffered camera-trap point locations. 4. Export the proportion of each habitat class within the buffers around each camera location, then save results in a CSV file connecting habitat variables to each camera-trap location. 5. Assign habitat variables to species activity data by a common variable- namely the camera site. 6. Model species temporal activity at each site using habitat variables as predictors- either using GAM or logistical regression. 7. Incorporate presence/absence of the other three target species into each species model to determine whether activity changes based on community interactions.

Q2. Describe the datasets you intend to use. You’ll need to have more than one dataset for this part of the project.

My primary spatial data includes: 1. USGS 10-meter DEM data from the UT AGRC - ruggedness/topography/elevation 2. SWReGAP landcover data link - landcover 3. LANDFIRE Existing Vegetation Cover link- edge 4. Camera-trap coordinates

These data are connected, through camera-trap site names, to species detection data collected during my undergraduate research with the USU Cougar Project. This dataset includes camera site, date, time, and species detected for each time the camera was self-triggered by an animal.

(See below for visualizations of each dataset)

Tidying your data (13)

Q3. Check and describe the projection of each dataset you intend to use and perform any necessary reprojections. If no reprojections are needed, lucky you!

I transformed each of the datasets into a UTM Zone 12 projection because of the local scale of my study area. This will also be of use when I am buffering because UTM has a clear unit - the meter - to work with.

# Set up R workspace
setwd('C:/Users/Maggie/Documents/GEOG4950/Project')
library(sp)
library(rgdal)
library(raster)
getClass("Spatial")
## Class "Spatial" [package "sp"]
## 
## Slots:
##                               
## Name:         bbox proj4string
## Class:      matrix         CRS
## 
## Known Subclasses: 
## Class "SpatialPoints", directly
## Class "SpatialMultiPoints", directly
## Class "SpatialGrid", directly
## Class "SpatialLines", directly
## Class "SpatialPolygons", directly
## Class "SpatialPointsDataFrame", by class "SpatialPoints", distance 2
## Class "SpatialPixels", by class "SpatialPoints", distance 2
## Class "SpatialMultiPointsDataFrame", by class "SpatialMultiPoints", distance 2
## Class "SpatialGridDataFrame", by class "SpatialGrid", distance 2
## Class "SpatialLinesDataFrame", by class "SpatialLines", distance 2
## Class "SpatialPixelsDataFrame", by class "SpatialPoints", distance 3
## Class "SpatialPolygonsDataFrame", by class "SpatialPolygons", distance 2
# Read in spatial data - note: I have already cropped these ones (roughly) to the extent of my study area
dem <- raster('DEM_cropped.tif')
gap <- raster('gap_cropped.tif')
evc <- raster('evc_crop.tif')

# Check coordinate systems - note: these were reprojected to UTM Zone 12 during the process of cropping
dem@crs
## CRS arguments:
##  +proj=utm +zone=12 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m
## +no_defs
gap@crs
## CRS arguments:
##  +proj=utm +zone=12 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m
## +no_defs
evc@crs
## CRS arguments:
##  +proj=utm +zone=12 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m
## +no_defs
# Create camera-trap point layer and set projection as UTM Zone 12 N.
cam_data <- read.csv('CameraUTMs.csv',sep="\t")
cam_data <- as.data.frame(cam_data)[1:37,] # need to find paperwork for a few sites at the end of the full CSV...
pts <- list(cam_data$UTM_Easting, cam_data$UTM_Northing)
prj = dem@crs
data <- as.data.frame(pts)
cams <- SpatialPointsDataFrame(data=data, coords=pts, proj4string=prj)
class(cams) # double check class as spatial points df
## [1] "SpatialPointsDataFrame"
## attr(,"package")
## [1] "sp"
cams@proj4string # double check in UTM 12 N
## CRS arguments:
##  +proj=utm +zone=12 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m
## +no_defs
names(cams@data) <- c("UTM_Easting","UTM_Northing")
cams@data <- cbind(cams@data,cam_data[2])

Q5. Extract two subsets of your data of interest to you using spdplyr or base R indexing. These subsets can be based on location in space or on attributes (i.e. counties in Utah or counties that start with “A”). Compare these two datasets visually.

I extracted camera-traps with cougar detections and plotted these against the number of deer photos at each camera site. Surprisingly enough, the cougar detections appear to be occuring at camera sites where less deer were photographed.

library(spdplyr)
## Warning: package 'spdplyr' was built under R version 3.4.3
## Loading required package: dplyr
## Warning: package 'dplyr' was built under R version 3.4.3
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:raster':
## 
##     intersect, select, union
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library("sp")
library("latticeExtra")
## Warning: package 'latticeExtra' was built under R version 3.4.3
## Loading required package: lattice
## Loading required package: RColorBrewer
library(RColorBrewer)
unique(total$Species)
##  [1] Snowshoe Hare     Squirrel          Flying Squirrel  
##  [4] Weasel            Coyote            Moose            
##  [7] Mule Deer         Elk               Human            
## [10] Domestic Dog      Horse (domestic)  Red Fox          
## [13] Raccoon           Cottontail Rabbit Cougar           
## [16] Unknown           Bird              Rat              
## [19] Striped Skunk     Cattle            Mountain Goat    
## [22] Mink              Domestic Sheep   
## 23 Levels: Bird Cattle Cottontail Rabbit Cougar Coyote ... Weasel
head(total)
##    Site       Date  Time         Species Inds          Cam_Model hour
## 1 03_01  12/2/2016  0:23   Snowshoe Hare    1 PC85 RAPIDFIRE PRO    0
## 2 03_01  11/3/2016 13:40        Squirrel    1 PC85 RAPIDFIRE PRO   13
## 3 03_01 11/18/2016 20:52 Flying Squirrel    1 PC85 RAPIDFIRE PRO   20
## 4 03_01  11/3/2016  9:05        Squirrel    1 PC85 RAPIDFIRE PRO    9
## 5 03_01 11/13/2016  0:18        Squirrel    1 PC85 RAPIDFIRE PRO    0
## 6 03_01 11/13/2016  0:18        Squirrel    1 PC85 RAPIDFIRE PRO    0
##   minute Season Behavior PUCO UTM_Easting UTM_Northing
## 1     23   FA16       NA    0      454449      4635345
## 2     40   FA16       NA    0      454449      4635345
## 3     52   FA16       NA    0      454449      4635345
## 4      5   FA16       NA    0      454449      4635345
## 5     18   FA16       NA    0      454449      4635345
## 6     18   FA16       NA    0      454449      4635345
puma <- total %>%
  group_by(Site) %>%
  filter(Species=="Cougar") %>%
  summarize(inds=sum(Inds))
## Warning: package 'bindrcpp' was built under R version 3.4.3
deer <- total %>%
  group_by(Site) %>%
  filter(Species=="Mule Deer") %>%
  summarize(inds=sum(Inds))
puma <- merge(cams,puma,by="Site")
for (i in 1:37) if(is.na(puma$inds[i])) puma$inds[i] <- 0 
deer <- merge(cams,deer,by="Site")
for (i in 1:37) if(is.na(deer$inds[i])) deer$inds[i] <- 0
class(puma); class(deer)
## [1] "SpatialPointsDataFrame"
## attr(,"package")
## [1] "sp"
## [1] "SpatialPointsDataFrame"
## attr(,"package")
## [1] "sp"
puma <- puma[puma$inds!=0,]
pal <- brewer.pal(n=11,name='RdYlGn')
p <- spplot(deer[2:37,], # plot census tracts
       "inds", # `AREAWATR` as choropleth sybmoblized variable
       col.regions=pal, # specify color palette
       cuts=10, # specify # breaks (n-1 from pal)
       col='transparent', 
       main="Cougar Detections Compared\n to Deer Photos at Camera-Traps") # title
p + layer(panel.points(puma$UTM_Easting, puma$UTM_Northing, col="black", pch=3), data=puma)

Q6. Create a new spatial object, perhaps defining a region or point of interest (3).

Creating an edge layer will require a binary layer coding trees vs. no trees. Here, I reclassified the Existing Vegetation Cover raster first into cover types, and then into trees/no trees.

new_cover <- c(10,100,110,120,150,154,100,109,119,129,154,172,0,1,2,3,4,5)
mat3 <- matrix(data=new_cover,ncol=3)
evc2 <- reclassify(evc,rcl=mat3) 
plot(evc2)

# 0 = developed, 1 = tree cover, 2 = shrubs, 3 = herbs, 4 = tree canopy, 5 = other canopy
mat4 <- matrix(data = c(0,1,1,1,5,0),byrow=TRUE,ncol=3)
trees <- reclassify(evc2,rcl=mat4)
plot(trees)

Visualize your data (8)

Q8. Create a spatial visualization of your data using tmap. Descibe the visualization as well as any interesting patterns or trends.

I plotted camera-traps where each species has been detected, while also color-coding by the monitoring season. This allows me to get some idea of the spatial and temporal distribution of detections for each species. I added labels to camera sites for easier interpretation of species interactions and removed the legend for color labels on camera sites, because the reason for grouping by site was mostly just to visualize which cameras were active concurrently. There’s a lot to unpack in the results, but here is what I found most interesting: * The cougar detections are clumped in the Right Hand Fork area at the center of the map, but it is also obvious that they have a wide distribution because camera-sites near the edges of the maps also have detections. * Coyote detections appear clumped in the Dry Canyon area. * Human detections are surprisingly well-distributed given that most of these locations are off-trail. * Moose detections appear to be clumped in two areas: Dry Canyon (bottom left) and the Ephraim’s grave area (bottom right). * Mule Deer detections are just about ubiquitous.

library(tmap)
total <- SpatialPointsDataFrame(data=data.frame(total), coords=list(total$UTM_Easting,total$UTM_Northing), proj4string=prj)
tmap_mode("plot")
## tmap mode set to plotting
tm_shape(total) +
  tm_dots(col='Season',size=0.8,legend.show=FALSE) + #specify color by monitoring season
  tm_view(basemaps="OpenTopoMap",alpha=1,basemaps.alpha=1) +
  tm_facets("Species",ncol=2,free.coords=FALSE) +
  tmap_options(tmap.limits=c(facets.plot=64,facets.view=23)) + 
  tm_compass(position=c("right","top"),type="4star") + #add compass
  tm_scale_bar() +
  tm_style_gray() + #specify background style
  tm_text(text="Site",size=2)