forked from AdamWilsonLabEDU/2024-geo511-spatial-data-science-case-studies-geo511_casestudy_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
750 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
title: "Case Study 04" | ||
author: Eleanor M. Byrne | ||
output: html_document | ||
--- | ||
|
||
## Packages/Lib | ||
|
||
Comments | ||
|
||
```{r} | ||
# This is for library/packages | ||
# install/load packages | ||
library(tidyverse) | ||
# install.packages('nycflights13') | ||
library(nycflights13) | ||
library(dplyr) | ||
``` | ||
|
||
## Opening/Data/information | ||
|
||
```{r} | ||
# Open and access the nyc flights | ||
airports <- nycflights13::airports | ||
flights <- nycflights13::flights | ||
``` | ||
|
||
```{r} | ||
# Find the maximum distance and the corresponding destination airport code | ||
highest <- flights %>% | ||
arrange(desc(distance)) %>% | ||
slice(1) %>% | ||
select(dest, distance) | ||
# It would be HNL (dest) | ||
``` | ||
|
||
```{r} | ||
# Join with airports data to get the full name of the airport | ||
farthest_airport_data <- highest %>% | ||
left_join(airports, by = c("dest" = "faa")) %>% | ||
select(name) # select the the destName column only | ||
``` | ||
|
||
```{r} | ||
# Convert the data.frame to a single character value with as.character() | ||
farthest_airport <- as.character(farthest_airport_data$name) | ||
# Print the farthest airport name | ||
farthest_airport | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
--- | ||
title: "Case Study 05" | ||
author: Eleanor M. Byrne | ||
date: August 1, 2020 | ||
output: github_document | ||
--- | ||
|
||
## Packages/Libraries | ||
|
||
```{r} | ||
# Step 1 | ||
# download the libraries/packages | ||
#install.packages("spData") | ||
#install.packages("sf") | ||
#install.packages("tidyverse") | ||
#install.packages("units") | ||
library(spData) | ||
library(sf) | ||
library(tidyverse) | ||
library(units) | ||
``` | ||
|
||
### Download the data/Read | ||
```{r} | ||
# download the data | ||
data(world) # this is the data from the spData package | ||
# load the lad | ||
data(us_states) | ||
# Step 2 | ||
albers="+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs" | ||
# transform to the albers equal area projection | ||
# # Transform world dataset to Albers Equal Area projection | ||
world_albers <- st_transform(world, crs = albers) | ||
# Canada | ||
# Filter the world dataset to include only Canada | ||
canada <- world_albers %>% | ||
filter(name_long == "Canada") # filter the world dataset for Canada | ||
# Set to 10km (10000m) | ||
# Buffer Canada by 10 km (10000 meters) | ||
canada_buffer <- st_buffer(canada, dist = 10000) | ||
# plot using ggplot | ||
ggplot() + | ||
geom_sf(data = canada_buffer, fill = "lightblue", color = "black") + | ||
ggtitle("Buffered Area of Canada (10 km)") + | ||
theme_minimal() | ||
``` | ||
### New York setup | ||
```{r} | ||
# Step 3 | ||
# Create one for New York | ||
# transform us_states dataset to the same Albers projection | ||
us_states_albers <- st_transform(us_states, crs = albers) | ||
# filter for NY | ||
new_york <- us_states_albers %>% | ||
filter(NAME == "New York") # New York and use the us_states_albers | ||
# Create border object by intersecting Canada buffer with New York | ||
border <- st_intersection(canada_buffer, new_york) | ||
``` | ||
### Plotting | ||
```{r} | ||
# Step 4 | ||
# Plot using ggplot and geom_sf() | ||
# Plot the border area using ggplot2 | ||
ggplot() + | ||
geom_sf(data = new_york, fill = 'blue', color = "red") + # New York outline | ||
geom_sf(data = border, fill = "yellow", color = "black") + # Intersection area | ||
ggtitle("Border Area Between Canada and New York") + | ||
theme_minimal() | ||
# Step 5 | ||
# Calculate the area of the intersected polygon | ||
area_sq_m <- st_area(border) # Area in square meters | ||
# Convert to km^2 | ||
area_sq_km <- set_units(area_sq_m, km^2) | ||
# Print the area in square kilometers | ||
print(area_sq_km) | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
title: "Case Study 06" | ||
author: Eleanor M. Byrne | ||
date: August 1, 2020 | ||
output: html_document | ||
--- | ||
|
||
### Packages/Libraries | ||
```{r} | ||
library(terra) | ||
library(spData) | ||
library(tidyverse) | ||
library(sf) | ||
library(ncdf4) | ||
``` | ||
|
||
### Data | ||
```{r} | ||
download.file("https://crudata.uea.ac.uk/cru/data/temperature/absolute.nc","crudata.nc", method="curl") # add the curl if there are issues | ||
# read in the data using the rast() function from the terra package | ||
tmean=rast("crudata.nc") | ||
# Inspect the tmean object | ||
print(tmean) | ||
plot(tmean) | ||
``` | ||
### Calculate the Maximum Temperature Observed: | ||
```{r} | ||
# Step 2: Calculate the maximum value | ||
tmean_max <- max(tmean) | ||
# Plot the maximum temperature to visualize the new raster layer | ||
plot(tmean_max, main = "Maximum Temperature") | ||
# Step 3: Extract the maximum temperature observed in each country | ||
# Use terra::extract() to get the maximum temperature for each country | ||
max_temp_per_country <- terra::extract(tmean_max, world, fun = max, na.rm = TRUE, small = TRUE) | ||
# Bind the original world dataset with the new summary of the temperature data | ||
world_clim <- bind_cols(world, max_temp_per_country) | ||
# Rename the column for clarity | ||
colnames(world_clim)[ncol(world_clim)] <- "max_temp" | ||
``` | ||
### Communicate your results | ||
```{r} | ||
# Plot the maximum temperature in each country polygon | ||
ggplot(world_clim) + | ||
geom_sf(aes(fill = max_temp), color = "black") + | ||
scale_fill_viridis_c(name = "Maximum\nTemperature (C)") + | ||
theme_minimal() + | ||
theme(legend.position = 'bottom') + | ||
ggtitle("Maximum Temperature in Each Country") | ||
# Find the hottest country in each continent | ||
hottest_continents <- world_clim %>% | ||
group_by(continent) %>% | ||
slice_max(order_by = max_temp, n = 1) %>% | ||
select(name_long, continent, max_temp) %>% | ||
arrange(desc(max_temp)) %>% | ||
st_set_geometry(NULL) | ||
# Print the hottest country in each continent | ||
print(hottest_continents) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
title: "Case Study 07" | ||
author: Eleanor M. Byrne | ||
format: html | ||
editor: visual | ||
--- | ||
### Library/Packages | ||
```{r} | ||
# library and packages | ||
library(tidyverse) | ||
library(reprex) | ||
library(sf) | ||
library(spData) | ||
data(world) | ||
``` | ||
### Practice plot | ||
```{r} | ||
ggplot(world,aes(x=gdpPercap, y=continent, color=continent))+ | ||
geom_density(alpha=0.5,color=F) | ||
``` | ||
### The Corrected Plot | ||
```{r} | ||
# Corrected code to achieve the desired figure | ||
ggplot(world, aes(x = gdpPercap, fill = continent)) + | ||
geom_density(alpha = 0.5) + | ||
labs(title = "Distribution of GDP per Capita by Continent", | ||
x = "GDP per Capita", | ||
y = "Density") + | ||
theme_minimal() | ||
``` | ||
### Copy the Code to Your Clipboard | ||
```{r} | ||
reprex({ | ||
# Load necessary libraries | ||
library(tidyverse) | ||
library(sf) | ||
library(spData) | ||
# Load the world data | ||
data(world) | ||
# Your initial code with corrections | ||
ggplot(world, aes(x = gdpPercap, fill = continent)) + | ||
geom_density(alpha = 0.5) + | ||
labs(title = "Distribution of GDP per Capita by Continent", | ||
x = "GDP per Capita", | ||
y = "Density") + | ||
theme_minimal() | ||
}, venue = "gh") | ||
``` | ||
### Post as an ‘issue’ in github | ||
```{r} | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
title: "Case Study 08" | ||
author: Eleanor M. Byrne | ||
output: html_document | ||
--- | ||
|
||
# The website | ||
|
||
The website was created and the link is https://github.com/AdamWilsonLabEDU/final-project-embyrne0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.