# Übungen zu Episode III #' /^--^\ /^--^\ /^--^\ #' \____/ \____/ \____/ #' / \ / \ / \ #' | | | | | | #' \__ __/ \__ __/ \__ __/ #' |^|^|^|^|^|^|^|^|^|^|^|^\ \^|^|^|^/ /^|^|^|^|^\ \^|^|^|^|^|^|^|^|^|^|^|^| #' | | | | | | | | | | | | |\ \| | |/ /| | | | | |\ \| | | | | | | | | | | | #' | | | | | | | | | | | | |/ /| | |\ \| | | | | |/ /| | | | | | | | | | | | #' | | | | | | | | | | | | |\/ | | | \/| | | | | |\/ | | | | | | | | | | | | #' ######################################################################### #' | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | #' | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ########################### # Lücken-Skript # Füllen Sie die Kommentare und beschreiben Sie, was die jeweilige Operation macht. ########################### # ?? library(tidyverse) setwd('~/wegweisR') dwd_gebietsmittel_lufttemperatur_datei <- 'regional_averages_tm_year.txt' dwd_gebietsmittel_lufttemperatur <- read_delim(dwd_gebietsmittel_lufttemperatur_datei, delim = ';', skip = 1, trim_ws = TRUE) # ?? dwd_gebietsmittel_lufttemperatur_long <- dwd_gebietsmittel_lufttemperatur %>% select(-Jahr_1, -X20) %>% pivot_longer(cols = -Jahr, names_to = 'Bundesland', values_to = 'Temperatur') # ?? dwd_gebietsmittel_lufttemperatur_long %>% filter(Bundesland == 'Deutschland') %>% ggplot(aes(x = Jahr, y = Temperatur)) + geom_line() + scale_x_continuous(name = 'Jahr', n.breaks = 30) + scale_y_continuous(name = 'Jahresmittel [Grad Celsius]', breaks = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), limits = c(0, 12)) + ggtitle(label = 'Lufttemperatur in Deutschland', subtitle = 'Daten vom Deutschen Wetterdienst') + theme(axis.text.x = element_text(angle = 45, hjust = 1)) # ?? dwd_gebietsmittel_lufttemperatur_long %>% filter(Bundesland != 'Deutschland') %>% ggplot(aes(x = Jahr, y = Temperatur)) + geom_line() + scale_x_continuous(name = 'Jahr', n.breaks = 10) + scale_y_continuous(name = 'Jahresmittel [Grad Celsius]', breaks = c(0, 5, 10), limits = c(0, 12)) + ggtitle(label = 'Lufttemperatur in Deutschland', subtitle = 'Daten vom Deutschen Wetterdienst') + theme(axis.text.x = element_text(angle = 45, hjust = 1)) + facet_wrap(vars(Bundesland)) ########################### # Code-Verständnis 2.0 # Der folgende Code enthält noch nicht gelernte Elemente. # Können Sie trotzdem beschreiben, was hier passiert? ########################### # ?? covid19_confirmedcases_datei <- 'time_series_covid19_confirmed_global_2020-04-16.csv' covid19_confirmedcases <- read_csv(covid19_confirmedcases_datei) # ?? str(covid19_confirmedcases) covid19_confirmedcases # ?? covid19_confirmedcases %>% filter(`Country/Region` == 'Germany') # ?? covid19_confirmedcases %>% filter(`Country/Region` == 'Germany') %>% select(`Country/Region`, `4/13/20`, `4/14/20`, `4/15/20`) # ?? covid19_confirmedcases_long <- covid19_confirmedcases %>% select(-`Province/State`, -Lat, -Long) %>% pivot_longer(-`Country/Region`, names_to = 'Date', values_to = 'Cases') covid19_confirmedcases_long # ?? covid19_confirmedcases_long %>% summarise(anzahl_laender = n_distinct(`Country/Region`)) # ?? covid19_confirmedcases_long %>% mutate(Date = as.Date(Date, format = '%m/%d/%y')) # ?? covid19_confirmedcases_long %>% filter(`Country/Region` == 'Germany') %>% mutate(Date = as.Date(Date, format = '%m/%d/%y')) %>% ggplot(aes(x = Date, y = Cases)) + geom_line() # ?? covid19_confirmedcases_long %>% filter(`Country/Region` %in% c('Germany', 'Austria', 'Switzerland', 'Italy', 'US')) %>% mutate(Date = as.Date(Date, format = '%m/%d/%y')) %>% ggplot(aes(x = Date, y = Cases, color = `Country/Region`)) + geom_line() ########################### # Code-Anpassungen # Kopieren Sie sich den Code so zusammen, dass er den Anforderungen gerecht wird. ########################### # Nutzen Sie die letzte Visualisierung als Ausgangspunkt: # Nutzen Sie gghighlight und heben Sie Deutschland hervor. # Teilen Sie die Grafik (ohne gghighlight) mit facet_wrap in die Länder auf. # Beschriften Sie die Achsen korrekt. # Ergänzen Sie die Visualisierung um Großbritannien.