When importing the three CVS files into our data set environment, we can see that next to all the data titles, it reads “63890 obs.” This indicates we have 63,890 objects and, thus, 63,890 different hexagons, as all their IDs are different. All three files possess the same HEX_IDs, displaying the animals presented in the same Hexagons for all data sets, 63,890 for all and total.
When utilizing “?merge,” I learned how to merge two data sets. Since I have three, I first merged Birds and Mammals, then used that merged file to merge Reptiles to it. This results in “merge_dat2,” with all the “HEX_ID” from all three data sets merged.
dat <- read.csv("~/Downloads/ANT Final Data/species richness csv files/bird layer.csv")
datm <- read.csv("~/Downloads/ANT Final Data/species richness csv files/mammal layer.csv")
datr <- read.csv("~/Downloads/ANT Final Data/species richness csv files/reptile layer.csv")
##HEX_ID merge of Birds and Mammals first
merge_dat1 <- merge(x = dat, y = datm, by = intersect(names(dat), names(datm)), by.x = "Hex_ID", by.y = "Hex_ID", all = FALSE, all.x = FALSE, all.y = FALSE, sort = TRUE, suffixes = c(".bird", ".mammal"), no.dups = TRUE, incomparables = NULL)
###HEX_ID merge of the previous merge (Birds/Mammals) with Reptiles
merge_dat2 <- merge(x = merge_dat1, y = datr, by = intersect(names(merge_dat1), names(datr)), by.x = "Hex_ID", by.y = "Hex_ID", all = FALSE, all.x = FALSE, all.y = FALSE, sort = TRUE, suffixes = c(".merged", ".reptile"), no.dups = TRUE, incomparables = NULL)
Merge of all three Data sets’ “HEX_ID” in merge_data2
Here are three Histogram graphs representing the frequency of Birds, Mammals, and Reptiles per Hexagon.
dat <- read.csv("~/Downloads/ANT Final Data/species richness csv files/bird layer.csv")
datm <- read.csv("~/Downloads/ANT Final Data/species richness csv files/mammal layer.csv")
datr <- read.csv("~/Downloads/ANT Final Data/species richness csv files/reptile layer.csv")
par(mfrow=c(1,3))
hist(dat$NtvBird, main = NULL, xlab = "Frequency of Birds Species", ylab = "Hexagon", col = blues9)
hist(datm$NtvMamm, main = "Species Richness Per Hexagon", xlab = "Frequency of Mammals Species", ylab = "Hexagon", col = blues9)
hist(datr$NtvRept, main = NULL, xlab = "Frequency of Reptiles Species ", ylab = "Hexagon", col = blues9)
3-Panel Histogram Graphs
Here we have another 3-panel graph, only now displaying a Scatter Plot relationship between Birds and Mammals, Mammals and Reptiles, and Reptiles and Birds. Using my merged data from the previous question, allowed me to ensure their HEX_ID overlaps. In order to display only the species present per hexagon, as both labels were in the new data, “NtvBird” or “NtvMamm,” making the coding easier.
par(mfrow=c(1,3))
### Bird vs. Mammal
transp <- function(col, alpha=.5){
res <- apply(col2rgb(col),2, function(c) rgb(c[1]/255, c[2]/255, c[3]/255, alpha))
return(res)
}
plot(merge_dat1$NtvBird, merge_dat1$NtvMamm, xlab = "Bird Species Richness", ylab = "Mammal Species Richness", main = "Bird and Mammal Species Richness", cex.main=1, cex=2.5, pch=16, col = transp("blue", alpha = 0.018))
###Mammal vs. Reptile
transp <- function(col, alpha=.5){
res <- apply(col2rgb(col),2, function(c) rgb(c[1]/255, c[2]/255, c[3]/255, alpha))
return(res)
}
plot(merge_dat2$NtvRept, merge_dat1$NtvMamm, xlab = "Reptile Species Richness", ylab = "Mammal Species Richness", main = "Bird and Mammal Species Richness", cex.main=1, cex=2.5, pch=16, col = transp("blue", alpha = 0.018))
###Bird vs. Reptile
transp <- function(col, alpha=.5){
res <- apply(col2rgb(col),2, function(c) rgb(c[1]/255, c[2]/255, c[3]/255, alpha))
return(res)
}
plot(merge_dat2$NtvRept, merge_dat1$NtvBird, xlab = "Reptile Species Richness", ylab = "Bird Species Richness", main = "Bird and Mammal Species Richness", cex.main=1, cex=2.5, pch=16, col = transp("blue", alpha = 0.018))
title("Relationships Between Species", outer=TRUE, cex.main = 1.5, line=-1)