library(tidyverse) library(haven) library(gesis) library(ggthemes) library(ggmap) s <- login(username = "", password = "") get_study_groups() # ALLBUS get_datasets("0007") %>% print(n = 100) # EVS get_datasets("0009") %>% print(n = 100) dir.create(file.path(".", "data")) download_dataset(s, doi = "4587", path = "./data", filetype = ".sav", purpose = 6) allbus_kum <- read_sav("data/ZA4587_v1-0-0.sav") dim(allbus_kum) names(allbus_kum) contact <- allbus_kum %>% select(year, eastwest, starts_with("mc"), wghtpt) %>% mutate(eastwest = as_factor(eastwest), eastwest = recode(eastwest, "ALTE BUNDESLAENDER" = "Westdeutschland", "NEUE BUNDESLAENDER" = "Ostdeutschland"), wghtpt = na_if(wghtpt, 0), mc01 = recode(as.numeric(mc01), "2"= 0), mc02 = recode(as.numeric(mc02), "2"= 0), mc03 = recode(as.numeric(mc03), "2"= 0), mc04 = recode(as.numeric(mc04), "2"= 0), mc01_w = mc01 * wghtpt, mc02_w = mc02 * wghtpt, mc03_w = mc03 * wghtpt, mc04_w = mc04 * wghtpt) contact_long <- contact %>% filter(!is.na(wghtpt)) %>% select(year, eastwest, mc01_w:mc04_w, wghtpt) %>% gather(key = type_of_contact, value = yes_no, -year, -eastwest, -wghtpt) %>% mutate(type_of_contact = recode(type_of_contact, "mc01_w" = "In der Familie", "mc02_w" = "Am Arbeitsplatz", "mc03_w" = "In der Nachbarschaft", "mc04_w" = "Im Freundeskreis")) %>% filter(!is.na(yes_no)) %>% group_by(year, eastwest, type_of_contact) %>% summarise(sum = sum(yes_no), n = sum(wghtpt)) %>% mutate (Anteil = (sum/n)*100) unique(contact_long$year) contact_long %>% ggplot(aes(x = year, y = Anteil, color = eastwest, shape = eastwest)) + geom_point(size = 2) + geom_line() + scale_y_continuous(expand = c(0,0), breaks = seq(0, 100, 10), limits = c(0,100), labels = c("0%", "10%", "20%", "30%", "40%" , "50%", "60%", "70%", "80%", "90%", "100%")) + scale_x_continuous(breaks = c(1980, 1984, 1988, 1990, 1994, 1996, 2000, 2002, 2006, 2010, 2012, 2016)) + facet_wrap(~type_of_contact, scales = "free") + labs(x = "", y = "Anteil der Befragten mit Kontakten", title = "Kontakte zwischen Deutschen und Ausländern 1980-2016\n", caption = "Quelle: ALLBUScompact - Kumulation 1980-2016.GESIS Datenarchiv, Köln.\nZA4587 Datenfile Version 1.0.0, doi:10.4232/1.13048") + theme(axis.text.x = element_text (angle = 90, vjust = 0.5), panel.grid.major.x = element_blank(), panel.grid.minor.x = element_blank(), legend.title = element_blank(), plot.title = element_text(face="bold", size = 12)) download_dataset(s, doi = "5250", path = "./data", filetype = ".sav", purpose = 6) unzip("./data/ZA5250_v2-1-0.sav.zip", exdir = "./data") allbus_2016 <- read_sav("data/ZA5250_v2-1-0.sav") dim(allbus_2016) migration_att <- allbus_2016 %>% select(eastwest, land, ma09, mp03) %>% mutate(eastwest = as_factor(eastwest), land = as_factor(land), land = fct_recode(land, "ST" = "SACHSEN-ANHALT", "SN" = "SACHSEN", "NI" = "NIEDERSACHSEN", "BW" = "BADEN-WUERTTEMBERG", "HE" = "HESSEN", "MV" = "MECKLENB.-VORPOMMERN", "BE" = "EHEM. BERLIN-OST", "BE" = "EHEM. BERLIN-WEST", "BB" = "BRANDENBURG", "RP" = "RHEINLAND-PFALZ", "SL" = "SAARLAND", "TH" = "THUERINGEN", "BY" = "BAYERN", "NW" = "NORDRHEIN-WESTFALEN", "SH" = "SCHLESWIG-HOLSTEIN", "HB" = "BREMEN", "HH" = "HAMBURG")) fremd_land <- migration_att %>% group_by(land) %>% summarise(n=n(), mean=mean(ma09, na.rm = T), sd=sd(ma09, na.rm = T)) %>% mutate(se=sd/sqrt(n)) %>% mutate(ic=se * qt((1-0.05)/2 + .5, n-1)) fremd_land bereicher_land <- migration_att %>% group_by(land) %>% summarise(n=n(), mean=mean(mp03, na.rm = T), sd=sd(mp03, na.rm = T)) %>% mutate(se=sd/sqrt(n)) %>% mutate(ic=se * qt((1-0.05)/2 + .5, n-1)) bereicher_land ggplot(fremd_land, aes(x = land, y = mean)) + geom_point(aes(size = n)) + geom_errorbar(aes(ymin = mean-ic, ymax = mean+ic), width = .1) + scale_y_continuous(expand = c(0,0), limits = c(1,7)) + labs(x = "", y = "", title = "Durch die vielen Ausländer in Deutschland fühlt man sich zunehmend \nals Fremder im eigenen Land.", subtitle = "1 = Stimme überhaupt nicht zu, 7 = Stimme voll und ganz zu", caption = "Quelle: ALLBUS 2016. GESIS Datenarchiv, Köln. ZA5250 Datenfile Version 2.1.0, doi:10.4232/1.12796") + theme_calc() ggplot(bereicher_land, aes(x = land, y = mean)) + geom_point(aes(size = n)) + geom_errorbar(aes(ymin = mean-ic, ymax = mean+ic), width = .1) + scale_y_continuous(expand = c(0,0), limits = c(1,7)) + labs(x = "", y = "", title = "Die in Deutschland lebenden Ausländer \nsind eine Bereicherung für die Kultur in Deutschland.", subtitle = "1 = Stimme überhaupt nicht zu, 7 = Stimme voll und ganz zu", caption = "Quelle: ALLBUS 2016. GESIS Datenarchiv, Köln. ZA5250 Datenfile Version 2.1.0, doi:10.4232/1.12796") + theme_calc() download_dataset(s, doi = "7500", path = "./data", filetype = ".sav", purpose = 6) unzip("./data/ZA7500_v1-0-0.sav.zip", exdir = "./data") evs_2017 <- read_sav("data/ZA7500_v1-0-0.sav") dim(evs_2017) pol_evs_2017 <- evs_2017 %>% select(country, v124, v131, v142, v144) %>% mutate(country = as_factor(country), v124 = recode(as.numeric(v124), "1" = 4, "2" = 3, "3" = 2, "4" = 1), v131 = recode(as.numeric(v131), "1" = 4, "2" = 3, "3" = 2, "4" = 1)) world <- map_data("world") pol_country_evs_2017 <- pol_evs_2017 %>% group_by(country) %>% summarize_all(mean, na.rm = T) pol_country_evs_2017 %>% anti_join(world, by = c("country" = "region")) world %>% select(region) %>% unique() pol_country_evs_2017 <- pol_country_evs_2017 %>% mutate(country = recode(country, `Slovak Republic` = 'Slovakia')) evs_map_2017 <- world %>% left_join(pol_country_evs_2017, by = c("region" = "country")) pol_country_evs_2017 %>% select(-country) %>% summary() ggplot(data = evs_map_2017, aes(x = long, y = lat, group = group, fill = v124)) + geom_polygon(color = "white") + xlim(-25, 47.0) + ylim(35, 70) + theme_map() + theme(plot.title = element_text(face="bold", size = 16)) + labs(title = "Vertrauen in die EU 2017", subtitle = "1 = Überhaupt kein Vertrauen, 4 = Sehr viel Vertrauen", fill = "", caption = "Quelle: European Values Study 2017: Integrated Dataset (EVS 2017). \nGESIS Datenarchiv, Köln. ZA7500 Datenfile Version 1.0.0, doi:10.4232/1.13090") + scale_fill_distiller(breaks = c(1, 1.5, 2, 2.5, 3, 3.5, 4), palette = "RdYlGn", direction = 1, limits = c(1.5,3.5)) ggplot(data = evs_map_2017, aes(x = long, y = lat, group = group, fill = v131)) + geom_polygon(color = "white") + xlim(-25, 47.0) + ylim(35, 70) + theme_map() + theme(plot.title = element_text(face="bold", size = 16)) + labs(title = "Vertrauen in die Regierung 2017", subtitle = "1 = Überhaupt kein Vertrauen, 4 = Sehr viel Vertrauen", fill = "", caption = "Quelle: European Values Study 2017: Integrated Dataset (EVS 2017). \nGESIS Datenarchiv, Köln. ZA7500 Datenfile Version 1.0.0, doi:10.4232/1.13090") + scale_fill_distiller(breaks = c(1, 1.5, 2, 2.5, 3, 3.5, 4), palette = "RdYlGn", direction = 1, limits = c(1.5,3.5)) ggplot(data = evs_map_2017, aes(x = long, y = lat, group = group, fill = v142)) + geom_polygon(color = "white") + xlim(-25, 47.0) + ylim(35, 70) + theme_map() + theme(plot.title = element_text(face="bold", size = 14)) + labs(title = "Wie wichtig ist es für Sie, in einem Land zu leben, \ndas demokratisch regiert wird?", subtitle = "1 = Überhaupt nicht wichtig, 10 = Absolut wichtig", fill = "", caption = "Quelle: European Values Study 2017: Integrated Dataset (EVS 2017). \nGESIS Datenarchiv, Köln. ZA7500 Datenfile Version 1.0.0, doi:10.4232/1.13090") + scale_fill_distiller(breaks = c(7, 7.5, 8, 8.5, 9, 9.5, 10), palette = "RdYlGn", direction = 1, limits = c(7, 10)) ggplot(data = evs_map_2017, aes(x = long, y = lat, group = group, fill = v144)) + geom_polygon(color = "white") + xlim(-25, 47.0) + ylim(35, 70) + theme_map() + theme(plot.title = element_text(face="bold", size = 13)) + labs(title = "Wie zufrieden sind Sie damit, wie das politische System \nin Ihrem Land heutzutage funktioniert?", subtitle = "1 = Überhaupt nicht zufrieden, 10 = Voll und ganz zufrieden", fill = "", caption = "Quelle: European Values Study 2017: Integrated Dataset (EVS 2017). \nGESIS Datenarchiv, Köln. ZA7500 Datenfile Version 1.0.0, doi:10.4232/1.13090") + scale_fill_distiller(breaks = c(3, 4, 5, 6, 7, 8), palette = "RdYlGn", direction = 1, limits = c(2.5, 8)) download_dataset(s, doi = "4800", path = "./data", filetype = ".sav", purpose = 6) unzip("./data/ZA4800_v4-0-0.sav.zip", exdir = "./data") evs_2008 <- read_sav("data/ZA4800_v4-0-0.sav") dim(evs_2008) pol_evs_2008 <- evs_2008 %>% select(country, v214, v222) %>% mutate(country = as_factor(country), v214 = recode(as.numeric(v214), "1" = 4, "2" = 3, "3" = 2, "4" = 1), v222 = recode(as.numeric(v222), "1" = 4, "2" = 3, "3" = 2, "4" = 1)) pol_country_evs_2008 <- pol_evs_2008 %>% group_by(country) %>% summarize_all(mean, na.rm = T) pol_country_evs_2008 %>% anti_join(world, by = c("country" = "region")) world %>% select(region) %>% unique() pol_country_evs_2008 <- pol_country_evs_2008 %>% mutate(country = recode(country, `Bosnia Herzegovina` = 'Bosnia and Herzegovina', `Slovak Republic` = 'Slovakia', `Russian Federation` = 'Russia', `Great Britain` = 'UK')) world <- world %>% mutate(region = ifelse(region == "UK" & subregion == "Northern Ireland", "Northern Ireland", ifelse(region == "Cyprus" & !is.na(subregion), "Northern Cyprus", region))) evs_map_2008 <- world %>% left_join(pol_country_evs_2008, by = c("region" = "country")) pol_country_evs_2008 %>% select(-country) %>% summary() ggplot(data = evs_map_2008, aes(x = long, y = lat, group = group, fill = v214)) + geom_polygon(color = "white") + xlim(-25, 47.0) + ylim(35, 70) + theme_map() + theme(plot.title = element_text(face="bold", size = 16)) + labs(title = "Vertrauen in die EU 2008", subtitle = "1 = Überhaupt kein Vertrauen, 4 = Sehr viel Vertrauen", fill = "", caption = "Quelle: European Values Study 2008: Integrated Dataset (EVS 2008). \nGESIS Datenarchiv, Köln. ZA4800 Datenfile Version 4.0.0, doi:10.4232/1.12458") + scale_fill_distiller(breaks = c(1, 1.5, 2, 2.5, 3, 3.5, 4), palette = "RdYlGn", direction = 1, limits = c(1.5,3.5)) ggplot(data = evs_map_2008, aes(x = long, y = lat, group = group, fill = v222)) + geom_polygon(color = "white") + xlim(-25, 47.0) + ylim(35, 70) + theme_map() + theme(plot.title = element_text(face="bold", size = 16)) + labs(title = "Vertrauen in die Regierung 2008", subtitle = "1 = Überhaupt kein Vertrauen, 4 = Sehr viel Vertrauen", fill = "", caption = "Quelle:European Values Study 2008: Integrated Dataset (EVS 2008). \nGESIS Datenarchiv, Köln. ZA4800 Datenfile Version 4.0.0, doi:10.4232/1.12458") + scale_fill_distiller(breaks = c(1, 1.5, 2, 2.5, 3, 3.5, 4), palette = "RdYlGn", direction = 1, limits = c(1.5,3.5))