From 4d56e9408644a50cc6bb371fbfbdcad1f22eaa27 Mon Sep 17 00:00:00 2001 From: tinan2001 Date: Tue, 8 Oct 2024 14:57:13 -0400 Subject: [PATCH] Case Study 6 --- week_06/case_study_06.Rmd | 46 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/week_06/case_study_06.Rmd b/week_06/case_study_06.Rmd index 2581f05..cc06426 100644 --- a/week_06/case_study_06.Rmd +++ b/week_06/case_study_06.Rmd @@ -1,7 +1,47 @@ --- title: "Case Study 06" -author: Your Name -date: August 1, 2020 +author: Tina Ni +date: October 8, 2024 output: github_document --- - \ No newline at end of file +```{r load packages} +library(terra) +library(spData) +library(tidyverse) +library(sf) +library(ncdf4) +library(ggplot2) +``` + +```{r download data} +download.file("https://crudata.uea.ac.uk/cru/data/temperature/absolute.nc","crudata.nc", method = "curl") +``` + +```{r making data} +#tmean is climate data + +tmean = rast ('crudata.nc') +max_val_pix = max(tmean) + +max_temp_country <- terra::extract (max_val_pix, world, fun = max, na.rm = TRUE, small =T) + +world_clim <- bind_cols(world, max_temp_country) +``` + +```{r plot data} +ggplot(data = world_clim)+ + geom_sf(aes(fill = max))+ + scale_fill_viridis_c (name="Maximum/nTemperature (C)")+ + theme(legend.position = 'bottom') +``` + +```{r make table about hottest continents} +hottest_continents <- world_clim |> + group_by(continent)|> + top_n(1,max)|> + arrange(desc(max)) |> + st_set_geometry(NULL) |> + select(name_long,continent, max) + +hottest_continents +``` \ No newline at end of file