Question 1: How many hexgons are in each of the three data sets?
A-> In the Hex_ID data sets there are a total of 63,890 hexagons which I derived from the output from: df_merged <- Reduce(function(x,y) merge(x,y, by = c(“Hex_ID”), all=TRUE), df_list, accumulate= FALSE)
Part A: Create a 3-pannel graph (tip: par(mfrow=c(1,3))) showing the three distributions of NtvMamm, NtvBird, and NtvRept. Make sure your answer includes both your R code and the graph.
Part B: Create a 3-pannel graph showing the relationship between (i) NtvMamm and NtvBird, (ii) NtvMamm and NtvRept, and (iii) NtvBird and NtvRept. Make sure your answer includes both your R code and the graph.
# 3-pannel graph showing distributions
## ## I used the ggplot function discussed in final lecture of the course. After researching into the function I computed the following code: ## citation: https://stackoverflow.com/questions/15458526/r-pass-variable-column-indices-to-ggplot2
g1 <- ggplot(df_merged, aes(x = NtvMamm)) +
geom_histogram(col = "yellow", fill = "yellow", alpha = .7) +
scale_x_continuous(breaks = seq(0, 80, 20), limits = c(0, 80)) +
guides(fill = FALSE, col = FALSE)
## Warning: The `<scale>` argument of `guides()` cannot be `FALSE`. Use "none" instead as
## of ggplot2 3.3.4.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
g2 <- ggplot(df_merged, aes(x = NtvBird)) +
geom_histogram(col = "blue", fill = "blue", alpha = .7) +
scale_x_continuous(breaks = seq(0, 250, 75), limits = c(0, 250)) +
guides(fill = FALSE, col = FALSE)
g3 <- ggplot(df_merged, aes(x = NtvRept)) +
geom_histogram(col = "maroon", fill = "maroon", alpha = .7) +
scale_x_continuous(breaks = seq(0, 50, 10), limits = c(0, 50)) +
guides(fill = FALSE, col = FALSE)
## To create my 3-pannel graph i reviewed the following source: https://stackoverflow.com/questions/54495107/arrange-three-plots-of-the-same-size-on-two-rows-in-ggplot2 ## My code resulted in the desired graphs; however, produced a warning message. I attempted to troubleshoot by using the recommendations found in ##https://stackoverflow.com/questions/48864211/binwidth-error-while-using-ggpairs
## https://stackoverflow.com/questions/34774120/set-number-of-bins-for-histogram-directly-in-ggplot
### To no avail, after researching the matter and multiple attempts I left my code unaltered as it still produced the graphs requested for the assignment.
g_all <- ggarrange(g1, g2, g3, ncol=3) %>%
annotate_figure(top = text_grob("Distributions of Birds vs Mammals vs Reptiles"))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 4 rows containing non-finite outside the scale range
## (`stat_bin()`).
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_bar()`).
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_bar()`).
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 1 row containing non-finite outside the scale range (`stat_bin()`).
## Removed 2 rows containing missing values or values outside the scale range
## (`geom_bar()`).
g_all
Caption: 3-Pannel Graph - Distributions of Number of Native Mammals vs Birds vs Reptiles
# 3-pannel graph showing relationships
## I again used the ggplot function, see sources above, to create the relationship graph of the data
## I decided to use a line rgaph to show the relationship between Mammals, Birds, and Reptiles.
##https://stackoverflow.com/questions/7005483/geom-smooth-what-are-the-methods-available
gr1 <- ggplot(df_merged, aes(x = NtvMamm, y = NtvBird)) +
geom_smooth(alpha = .5, method = "lm", se = TRUE, fullrange = TRUE, col = "yellow") +
labs(title = "Relationship Between Mammals & Birds") +
theme(plot.title = element_text(hjust = .5))
gr2 <- ggplot(df_merged, aes(x = NtvMamm, y = NtvRept)) +
geom_smooth(alpha = .5, method = "lm", se = TRUE, fullrange = TRUE, col = "blue") +
labs(title = "Relationship Between Mammals & Reptiles") +
theme(plot.title = element_text(hjust = .5))
gr3 <- ggplot(df_merged, aes(x = NtvBird, y = NtvRept)) +
geom_smooth(alpha = .5, method = "lm", se = TRUE, fullrange = TRUE, col = "maroon") +
labs(title = "Relationship Between Birds & Reptiles") +
theme(plot.title = element_text(hjust = .5))
gr_all <- ggarrange(gr1, gr2, gr3, ncol=1, nrow=3)
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
gr_all
Caption: 3-Pannel Graph - Relationship Between Native Mammals vs Native Birds vs Native Reptiles
Question 2:
Create a map in GQIS reflecting the Species Bird Richness in California, add a scale and legend to your map.
In what part(s) of California is the native bird species the highest? The lowest?
A-> In reviewing the attribute table of the shapefile, the data reflects that the lowest count of native bird species is in the county of Siskiyou. Where the highest native bird species count pertains to the San Luis Obispo area which has about 240 species.