From a22f1a38648d6d1037a5a4bce85fd725c641aa3a Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Thu, 19 Sep 2024 18:10:48 +0000 Subject: [PATCH 01/14] Setting up GitHub Classroom Feedback From a0cb16d516c4345bb46f975ea8034e15332dfa5f Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Thu, 19 Sep 2024 18:10:51 +0000 Subject: [PATCH 02/14] add deadline --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5455607..f63d27e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/BRmhFFxj) # Repository to hold class activities for GEO511 ## Overview From 2183dbd44ea3ca98715e1986af73043fb6e9c325 Mon Sep 17 00:00:00 2001 From: Andrea Harder Date: Sat, 12 Oct 2024 12:10:57 -0400 Subject: [PATCH 03/14] Case Study 1 commit from R studio --- week_01/CaseStudy1.R | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 week_01/CaseStudy1.R diff --git a/week_01/CaseStudy1.R b/week_01/CaseStudy1.R new file mode 100644 index 0000000..1a8efad --- /dev/null +++ b/week_01/CaseStudy1.R @@ -0,0 +1,31 @@ +#Define the link to the data +library(tidyverse) + +# define the link to the data - you can try this in your browser too. Note that the URL ends in .txt. +dataurl="https://data.giss.nasa.gov/tmp/gistemp/STATIONS_v4/tmp_USW00014733_14_0_1/station.csv" + +#the next line tells the NASA site to create the temporary file +httr::GET("https://data.giss.nasa.gov/cgi-bin/gistemp/stdata_show_v4.cgi?id=USW00014733&ds=14&dt=1") + +temp=read_csv(dataurl, + na="999.90", # tell R that 999.90 means missing in this dataset + skip=1, # we will use our own column names as below so we'll skip the first row + col_names = c("YEAR","JAN","FEB","MAR", # define column names + "APR","MAY","JUN","JUL", + "AUG","SEP","OCT","NOV", + "DEC","DJF","MAM","JJA", + "SON","metANN")) + +#Explore +View(temp) +summary(temp) + +#Graph annual mean temperature JJA +ggplot(temp,aes(YEAR,JJA))+ + geom_point() + + geom_line() + + geom_smooth() + + xlab("Year") + ylab("Mean Summer Temperature (C)")+ + ggtitle("Mean Summer Temperatures in Buffalo, NY") + +ggsave From 0cdaf456b8efe83f90a2e0885e41d655df9fcd00 Mon Sep 17 00:00:00 2001 From: Andrea Harder Date: Thu, 31 Oct 2024 11:15:35 -0400 Subject: [PATCH 04/14] Case study 1 --- week_01/case_study_01.R | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/week_01/case_study_01.R b/week_01/case_study_01.R index 6bc1053..e09b581 100644 --- a/week_01/case_study_01.R +++ b/week_01/case_study_01.R @@ -1,2 +1,16 @@ +#Load the iris dataset data(iris) +# +iris$Sepal.Length +iris$Sepal.Width +iris$Petal.Length +iris$Petal.Width +iris$Species + +#Define new variable for petal length mean +petal_length_mean <-mean(Petal.Length) +petal_length_mean + +#Plot Histogram for Petal Length +hist(Petal.Length) \ No newline at end of file From bced64366263854723ed7178c3c3aba2fe229b8b Mon Sep 17 00:00:00 2001 From: Andrea Harder Date: Thu, 31 Oct 2024 12:00:54 -0400 Subject: [PATCH 05/14] Case study 2 --- week_02/case_study_02.R | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/week_02/case_study_02.R b/week_02/case_study_02.R index e69de29..c469a44 100644 --- a/week_02/case_study_02.R +++ b/week_02/case_study_02.R @@ -0,0 +1,31 @@ +#Define the link to the data +library(tidyverse) + +#define the link to the data - you can try this in your browser too. Note that the URL ends in .txt. +dataurl="https://data.giss.nasa.gov/tmp/gistemp/STATIONS_v4/tmp_USW00014733_14_0_1/station.csv" + +#the next line tells the NASA site to create the temporary file +httr::GET("https://data.giss.nasa.gov/cgi-bin/gistemp/stdata_show_v4.cgi?id=USW00014733&ds=14&dt=1") + +temp=read_csv(dataurl, + na="999.90", # tell R that 999.90 means missing in this dataset + skip=1, # we will use our own column names as below so we'll skip the first row + col_names = c("YEAR","JAN","FEB","MAR", # define column names + "APR","MAY","JUN","JUL", + "AUG","SEP","OCT","NOV", + "DEC","DJF","MAM","JJA", + "SON","metANN")) + +#Explore +View(temp) +summary(temp) + +#Graph annual mean temperature JJA +ggplot(temp,aes(YEAR,JJA))+ + geom_point() + + geom_line() + + geom_smooth() + + xlab("Year") + ylab("Mean Summer Temperature (C)")+ + ggtitle("Mean Summer Temperatures in Buffalo, NY") + +ggsave From 1185da125efdd2ad0cc468f1b72e974008ac59b7 Mon Sep 17 00:00:00 2001 From: Andrea Harder Date: Thu, 31 Oct 2024 12:03:35 -0400 Subject: [PATCH 06/14] Case study 3 --- week_03/case_study_03.R | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/week_03/case_study_03.R b/week_03/case_study_03.R index 0519ecb..4e53cd6 100644 --- a/week_03/case_study_03.R +++ b/week_03/case_study_03.R @@ -1 +1,30 @@ - \ No newline at end of file +#Load necessary packages +library(ggplot2) +library(gapminder) +library(dplyr) + +#Plot 1 +Filtered <- filter(gapminder, country != "Kuwait") +ggplot(Filtered, aes(lifeExp, gdpPercap, color = continent, size = pop/100000)) + + geom_point() + + facet_wrap(~year,nrow=1) + + scale_y_continuous(trans = "sqrt") + + theme_bw() + + labs(x = "Life Expectancy", y = "GDP per capita", color = "Continent", size = "Population(100k)") +ggsave(filename = "plot1.png", plot = last_plot(), width = 15, height = 5, units = "in") + +#Plot2 +gapminder_continent <- group_by(Filtered, continent, year) %>% + summarize(gdpPercapweighted = weighted.mean(x = gdpPercap, y = pop), pop = sum(as.numeric(pop))) + +ggplot(Filtered, x = year, y = gdpPercap)+ + geom_line(data = Filtered, aes(x= year, y = gdpPercap, group = country, color = continent))+ + geom_point(data = Filtered, aes(x= year, y = gdpPercap, color = continent))+ + geom_line(data = gapminder_continent, aes(x= year, y = gdpPercapweighted))+ + geom_point(data= gapminder_continent, aes(x= year, y = gdpPercapweighted, size = pop/100000))+ + facet_wrap(~continent,nrow=1)+ + theme_bw()+ + labs(x = "Year", y = "GDP per capita", size = "Population(100k)", color = "Continent" ) +ggsave(filename = "plot2.png", plot = last_plot(), width = 15, height = 5, units = "in") + + From d195e141e43dafa60834be2ca1cb3020b6252662 Mon Sep 17 00:00:00 2001 From: Andrea Harder Date: Thu, 31 Oct 2024 12:11:24 -0400 Subject: [PATCH 07/14] Case study 4 --- week_04/case_study_04.R | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 week_04/case_study_04.R diff --git a/week_04/case_study_04.R b/week_04/case_study_04.R new file mode 100644 index 0000000..25f539b --- /dev/null +++ b/week_04/case_study_04.R @@ -0,0 +1,19 @@ +library(tidyverse) +library(nycflights13) +library(dplyr) + +#Rename faa column in airports table to match dest column in flights table +colnames(airports)[1] = "dest" + +#Join airports and flights table by dest +Flights_airports<- flights %>% + left_join(airports, by = "dest") + +#Arrange by distance to find furthest airport +farthest_airport<- Flights_airports %>% + filter(distance == max(distance)) %>% + select(name) %>% + distinct() %>% + as.character() + +head(farthest_airport) From f1cc26369621e189d5600fe61a6b021e6b398884 Mon Sep 17 00:00:00 2001 From: Andrea Harder Date: Thu, 31 Oct 2024 12:19:09 -0400 Subject: [PATCH 08/14] Case study 5 --- week_05/case_study_05.R | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 week_05/case_study_05.R diff --git a/week_05/case_study_05.R b/week_05/case_study_05.R new file mode 100644 index 0000000..b87d1c8 --- /dev/null +++ b/week_05/case_study_05.R @@ -0,0 +1,27 @@ +#load libraries +library(spData) +library(sf) +library(tidyverse) + +#transform the data +world_transformed <- st_transform(world, "+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") +states_transformed <- st_transform(us_states, "+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") + +#filter the data frames for Canada and NY +Canada <- world_transformed %>% + filter(name_long == "Canada")%>% + st_buffer(10000) + +NY <- states_transformed %>% + filter(NAME == "New York") +#create a 'border' object +Canada_NY<- st_intersection(Canada,NY) + +#create map +ggplot()+ + geom_sf(data = NY)+ + geom_sf(data = Canada_NY, aes(fill="red"), show.legend = FALSE) + + ggtitle("New York Land within 10km") + + + From 02ebd7c06dbead78477511790710c91d537df7d8 Mon Sep 17 00:00:00 2001 From: Andrea Harder Date: Thu, 31 Oct 2024 12:23:31 -0400 Subject: [PATCH 09/14] Case study 6 --- week_06/case_study_06.R | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 week_06/case_study_06.R diff --git a/week_06/case_study_06.R b/week_06/case_study_06.R new file mode 100644 index 0000000..24ea6c5 --- /dev/null +++ b/week_06/case_study_06.R @@ -0,0 +1,35 @@ +library(terra) +library(spData) +library(tidyverse) +library(sf) +library(dplyr) +library(ncdf4) +library(knitr) + +download.file("https://crudata.uea.ac.uk/cru/data/temperature/absolute.nc","crudata.nc", method="curl") + +#Prepare Climate Data +tmean=rast("crudata.nc") + +#Calculate the max temp observed in each country +MaxObserved <- max(tmean) +plot(MaxObserved) +extract <- terra::extract(MaxObserved, world, fun=max, na.rm=1, small=1) +world_clim <- bind_cols(world, extract) + +#Map the results +ggplot(world_clim)+ + geom_sf(aes(fill = max))+ + scale_fill_viridis_c(name="Maximum\nTemperature (C)")+ + theme(legend.position = 'bottom') + +#Create a summary table +world_clim_group <- world_clim %>% + group_by(continent) +Top <- top_n(world_clim_group, 1, max) + +hottest_continents <- as_tibble(Top) %>% + select(2,3,13) %>% + arrange(desc(max)) + +kable(hottest_continents, file = "html", col.name = c("Name", "Continent", "Max Temp")) From b49cff5defcc8f5355aeb4ffaef2835606b64eca Mon Sep 17 00:00:00 2001 From: Andrea Harder Date: Tue, 12 Nov 2024 19:44:36 -0500 Subject: [PATCH 10/14] Case study 11 commit --- week_11/case_study_11.R | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 week_11/case_study_11.R diff --git a/week_11/case_study_11.R b/week_11/case_study_11.R new file mode 100644 index 0000000..a15b6d0 --- /dev/null +++ b/week_11/case_study_11.R @@ -0,0 +1,45 @@ +library(tidyverse) +library(spData) +library(sf) +library(mapview) +library(foreach) +library(doParallel) +library(tidycensus) +registerDoParallel(4) +getDoParWorkers() + +#Get census API key +census_api_key("") + +#Download block-level data by race +race_vars <- c( + "Total Population" = "P1_001N", + "White alone" = "P1_003N", + "Black or African American alone" = "P1_004N", + "American Indian and Alaska Native alone" = "P1_005N", + "Asian alone" = "P1_006N", + "Native Hawaiian and Other Pacific Islander alone" = "P1_007N", + "Some Other Race alone" = "P1_008N", + "Two or More Races" = "P1_009N") + options(tigris_use_cache = TRUE) #store the shapefiles + +#Get 2020 block-level data by race in Erie County +erie <- get_decennial(geography = "block", variables = race_vars, year=2020, + state = "NY", county = "Erie County", geometry = TRUE, + sumfile = "pl", cache_table=T) %>% #summary file that contains race data; cache for quick access + st_crop(c(xmin=-78.9,xmax=-78.85,ymin=42.888,ymax=42.92)) #crop the data + +#Organize categorical data by race +ErieRace <- as.factor(erie$variable) + +#For each category filter to include one race at a time +Foreach <- foreach(race = levels(ErieRace), .combine = rbind) %do% { + filtered <- erie %>% + filter(variable == race) +#Generate random points for each resident + points <- filtered %>% + st_sample(size=.$value) %>% + st_as_sf() %>% + mutate(variable = race)} #mutate to add a column set to race + +mapview(Foreach, zcol = "variable", cex = 2) From b937bd12db120a60ceeece26b8cd6bb433b0c802 Mon Sep 17 00:00:00 2001 From: Andrea Harder Date: Tue, 12 Nov 2024 19:57:40 -0500 Subject: [PATCH 11/14] Case study 9 commit --- week_09/case_study_09.R | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 week_09/case_study_09.R diff --git a/week_09/case_study_09.R b/week_09/case_study_09.R new file mode 100644 index 0000000..019c75c --- /dev/null +++ b/week_09/case_study_09.R @@ -0,0 +1,45 @@ +library(sf) +library(tidyverse) +library(ggmap) +library(spData) +library(dplyr) +library(ggplot2) +data(world) +data(us_states) + +#Download a csv +dataurl="https://www.ncei.noaa.gov/data/international-best-track-archive-for-climate-stewardship-ibtracs/v04r01/access/csv/ibtracs.NA.list.v04r01.csv" +storm_data <- read_csv(dataurl) + +#Wrangle the data +storm_data2 <- storm_data %>% +mutate(year = year(ISO_TIME)) %>% +filter(year >= 1950) %>% +mutate_if(is.numeric, function(x) ifelse(x==-999.0,NA,x)) %>% +mutate(decade=(floor(year/10)*10)) %>% +st_as_sf(coords=c("LON","LAT"),crs=4326) + +region <- storm_data2 %>% + st_bbox() + +#Make the first plot +ggplot(world) + + geom_sf() + + facet_wrap(~decade) + + stat_bin2d(data=storm_data2, aes(y=st_coordinates(storm_data2)[,2], x=st_coordinates(storm_data2)[,1]),bins=100) + + scale_fill_distiller(palette="YlOrRd", trans="log", direction=-1, breaks = c(1,10,100,1000)) + + coord_sf(ylim=region[c(2,4)], xlim=region[c(1,3)])+ + xlab(NULL)+ + ylab(NULL) + + +#Five states with the most storms +states <- st_transform(us_states, st_crs(storm_data2)) %>% + select(state=NAME) +storm_states <- st_join(storm_data2, states, join = st_intersects, left = FALSE) %>% + group_by(state) %>% + summarize(storms=length(unique(NAME))) %>% + arrange(desc(storms)) %>% + slice(1:5) + +print(storm_states) From 9b8ee8eb924c579859afd8430c7ee2d0426f5d83 Mon Sep 17 00:00:00 2001 From: Andrea Harder Date: Tue, 12 Nov 2024 20:24:48 -0500 Subject: [PATCH 12/14] Case study 7 commit --- week_07/case_study_7.R | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 week_07/case_study_7.R diff --git a/week_07/case_study_7.R b/week_07/case_study_7.R new file mode 100644 index 0000000..668cf23 --- /dev/null +++ b/week_07/case_study_7.R @@ -0,0 +1,9 @@ +library(tidyverse) +library(reprex) +library(sf) +library(spData) +data(world) + +ggplot(world,aes(x=gdpPercap, y=continent, color=continent))+ + geom_density(alpha=0.5,color=F) +reprex(venue="gh") From 5f169b4577593955d79f049a433f5d3e6b9f8097 Mon Sep 17 00:00:00 2001 From: Andrea Harder Date: Thu, 12 Dec 2024 14:41:16 -0500 Subject: [PATCH 13/14] Commit case study 12 --- week_12/CaseStudy12.R | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 week_12/CaseStudy12.R diff --git a/week_12/CaseStudy12.R b/week_12/CaseStudy12.R new file mode 100644 index 0000000..f0f2c39 --- /dev/null +++ b/week_12/CaseStudy12.R @@ -0,0 +1,27 @@ +library(tidyverse) +library(htmlwidgets) +library(widgetframe) +library(xts) +library(dygraphs) +library(openmeteo) + +#Download weather data for Buffalo, NY +d<- weather_history(c(43.00923265935055, -78.78494250958327),start = "2023-01-01",end=today(), + daily=list("temperature_2m_max","temperature_2m_min","precipitation_sum")) %>% + mutate(daily_temperature_2m_mean=(daily_temperature_2m_max+daily_temperature_2m_min)/2) + +#Order the variables +xts <- select(d, daily_temperature_2m_min,daily_temperature_2m_mean, daily_temperature_2m_max)%>% + xts(order.by=d$date) + +Precip <- select(d, daily_precipitation_sum)%>% + xts(order.by=d$date) + +#Make the graphs +dygraph(xts, main = "Daily Maximum Temperature in Buffalo, NY") %>% + dySeries("daily_temperature_2m_mean")%>% +dyRangeSelector(dateWindow = c("2023-01-01", "2024-10-31")) + +dygraph(Precip, main = "Daily Precipitation in Buffalo, NY")%>% +dyRangeSelector(dateWindow = c("2023-01-01", "2024-10-31")) + From 038538a81549974d66eb6dd6fdb13a60fac0271f Mon Sep 17 00:00:00 2001 From: Andrea Harder Date: Thu, 12 Dec 2024 14:43:39 -0500 Subject: [PATCH 14/14] Case study 8 commit --- week_08/case_study_08.qmd | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 week_08/case_study_08.qmd diff --git a/week_08/case_study_08.qmd b/week_08/case_study_08.qmd new file mode 100644 index 0000000..93c64e3 --- /dev/null +++ b/week_08/case_study_08.qmd @@ -0,0 +1,35 @@ +--- +title: "Carbon Dioxide Concentrations at Mona Loa Observatory" +author: "Andrea Harder" +format: + html: default + pptx: default + docx: default + gfm: default +editor: visual +--- + +```{r setup, include = FALSE} +library(readr) +library(quarto) +library(tidyverse) +library(ggplot2) +library(dplyr) +Filtered <- read_table("ftp://aftp.cmdl.noaa.gov/products/trends/co2/co2_annmean_mlo.txt", skip = 44)%>% + rename("Year"="#", "mean"="year", "#"="mean") +Filtered2<- Filtered %>% + slice(1:5) +``` + +```{r, echo = FALSE} +colnames(Filtered) <- c("Year", "Mean", "num") +ggplot() + + geom_line(data = Filtered, aes(x = Year, y = Mean, color = "red"))+ + labs(x= "Year", y="Mauna Loa Annual Mean Co2(ppm)", title = "Annual Mean Carbon Dioxide Concentrations", subtitle = " 1959-Present")+ + theme(legend.position = "none", plot.title = element_text(hjust = .5), plot.subtitle = element_text(hjust = .5)) + +``` + +```{r, echo = FALSE} +knitr::kable(Filtered2[1:2]) +```