1. Packages einlesen


2. Daten einlesen

  • ich benutze Die Daten aus dem Ess
#Einlesen vom ESS-Datensatz
ess <- read.spss("/Users/krispinkruger/Krüger/MDAR mit R Remer/Data/ESS9e02.sav", use.value.labels = FALSE, to.data.frame = TRUE, reencode = TRUE)
## re-encoding from UTF-8
#Variablen anzeigen 
#View(ess)
#names(ess)
nrow(ess) #-->  47086 Befragte 
## [1] 47086
ncol(ess) #--> 557 Variablen 
## [1] 557

Outline für Shiny Anwendung

2.1 Subset erstellen mit den relevanten Variablen

Ich benutze nur die Trust-Variablen für die verschiedenen hierachischen Ebenen aus dem Ess, um die EU-Länder miteinader zu vergleichen.

  • trstprl = Trust in countries parliament (0-10, No trust at all - Complete trust)

  • trstep = Trust in the european parliament (0-10, No trust at all - Complete trust)

  • trstun = Trust in the UN (0-10, No trust at all - Complete trust)

    • Die benötigten Variablen sind also die 3 Trustvariablen und die cntry-Variable, aus welchem Land die befragten kommen (cntry)
#Subset erstelln 
df_hirachy <- subset(ess, select = c("trstprl", "trstep", "trstun", "cntry"))
#View(df_hirachy)
#esquisser(df_hirachy)

# Zuerst müssen wir die Anzahl der NAs in jeder Variablen berechnen
nas_count <- colSums(is.na(df_hirachy))
# Jetzt können wir den Anteil an NAs im Vergleich zu den vollständigen  Variabeln berechnen
nas_percentage <- nas_count / nrow(df_hirachy)
# Ausgabe des Anteils
nas_percentage
##    trstprl     trstep     trstun      cntry 
## 0.02382874 0.07231449 0.08958077 0.00000000
#--> Wir haben bei allen drei Variablen einen Anteil an Na's von <10%, was dafür spricht, das es keine systematische Problematik gibt und wir die NA's einfach entfernen können. Imputieren ist hier nicht nötig, da wir trotz der NA's immernoch eine enorm große Fallzahl haben. 
#Nas entfernen 
df.na <-df_hirachy %>% drop_na()
sum(is.na(df_hirachy)) #alle Na's sind entfernt 
## [1] 8745
length(df_hirachy) / sum(is.na(df_hirachy))
## [1] 0.0004574042
#Anteil von Na`s sind vernachlässigbar, da sie gegen Null gehen und nur 0,004% betragen

# 3 höchste Werte
df.na %>%
  group_by(cntry) %>%
  top_n(3, trstprl)
## # A tibble: 942 × 4
## # Groups:   cntry [27]
##    trstprl trstep trstun cntry
##      <dbl>  <dbl>  <dbl> <chr>
##  1      10      6      6 AT   
##  2      10      8      7 AT   
##  3      10      9      8 AT   
##  4      10      5      5 AT   
##  5      10      3      7 AT   
##  6      10     10     10 AT   
##  7      10      6      8 AT   
##  8      10     10     10 AT   
##  9      10      9      8 AT   
## 10      10      9      9 AT   
## # … with 932 more rows
# 3 niedrigste Werte
df.na %>%
  group_by(cntry) %>%
  top_n(-3, trstprl)
## # A tibble: 4,645 × 4
## # Groups:   cntry [27]
##    trstprl trstep trstun cntry
##      <dbl>  <dbl>  <dbl> <chr>
##  1       0      0      2 AT   
##  2       0      3      0 AT   
##  3       0      0      0 AT   
##  4       0      2      2 AT   
##  5       0      0      0 AT   
##  6       0      0      0 AT   
##  7       0      0      0 AT   
##  8       0      0      0 AT   
##  9       0      0      0 AT   
## 10       0      0      0 AT   
## # … with 4,635 more rows

3. Variablen vorbereiten

Sollte für den Vergleich der EU-Länder die Means miteinander verglichen werden, um Extremfälle und Ausreißer ausgleichen zu können oder soll die komplette Skala benutzt werden?

3.1 Vertrauen auf Landesebene

prozentuale Verteilung des Vertrauens und Aufteilung nach den verschiedenen Ländern

#Kolmogorov-Smirnoff-Test
ks.test(df.na$trstprl, "pnorm", mean = mean(df.na$trstprl), sd = sd(df.na$trstprl))
## Warning in ks.test.default(df.na$trstprl, "pnorm", mean = mean(df.na$trstprl), :
## ties should not be present for the Kolmogorov-Smirnov test
## 
##  Asymptotic one-sample Kolmogorov-Smirnov test
## 
## data:  df.na$trstprl
## D = 0.1205, p-value < 2.2e-16
## alternative hypothesis: two-sided
DescTools::Desc(df.na$trstprl)
## ------------------------------------------------------------------------------ 
## df.na$trstprl (numeric)
## 
##   length       n    NAs  unique     0s   mean  meanCI'
##   41'542  41'542      0      11  4'645   4.50    4.48
##           100.0%   0.0%          11.2%           4.53
##                                                      
##      .05     .10    .25  median    .75    .90     .95
##     0.00    0.00   3.00    5.00   7.00   8.00    9.00
##                                                      
##    range      sd  vcoef     mad    IQR   skew    kurt
##    10.00    2.65   0.59    2.97   4.00  -0.11   -0.82
##                                                      
## 
##     value   freq   perc  cumfreq  cumperc
## 1       0  4'645  11.2%    4'645    11.2%
## 2       1  2'200   5.3%    6'845    16.5%
## 3       2  3'375   8.1%   10'220    24.6%
## 4       3  4'471  10.8%   14'691    35.4%
## 5       4  4'161  10.0%   18'852    45.4%
## 6       5  7'258  17.5%   26'110    62.9%
## 7       6  4'870  11.7%   30'980    74.6%
## 8       7  4'979  12.0%   35'959    86.6%
## 9       8  3'474   8.4%   39'433    94.9%
## 10      9  1'167   2.8%   40'600    97.7%
## 11     10    942   2.3%   41'542   100.0%
## 
## ' 95%-CI (classic)

#Vertrauen auf Landesebene 
g1 <- ggplot(df.na, aes( trstprl)) +
 geom_bar(aes(y = after_stat(count)/sum(after_stat(count))),
 fill = "brown", color = "lightblue")+
 scale_y_continuous(labels = scales::percent) +
 scale_x_continuous(breaks = seq(0,10),
 labels = c("kein Vertrauen",
 "1", "2", "3", "4", "5", "6", "7", "8", "9",
 "komplettes Vertrauen"))+
 labs(title = "Vertrauen auf nationaler Ebene (Parlament)",
 caption = "Data: ESS9",
 y = "Häufigkeit in Prozent",
 x ="Vertrauen in Landesparlament")+
 theme_bw()
g1

ggsave(filename = "Landesparlament.png", plot = g1, width = 8, height  = 7, dpi = 1000)

#Aufteilung nach Ländern
g2 <- ggplot(df.na, aes( trstprl)) +
 geom_bar(aes(y = after_stat(count)/sum(after_stat(count))),
 fill = "brown", color = "lightblue")+
 scale_y_continuous(labels = scales::percent) +
 labs(title = "Vertrauen in nationales Parlament",
 caption = "Data: ESS9",
 y = "Häufigkeit in Prozent",
 x ="Vertrauen in nationales Parlament")+
 theme_bw()+
facet_grid(~cntry)
g2

ggplotly()
ggsave(filename = "Landesparlament_nach_Ländern.png", plot = g2, width = 12, height  = 5, dpi = 600)


g3 <- ggplot(data = df.na, aes(x = trstprl, y = after_stat(count)/sum(after_stat(count)))) +
  geom_bar(stat = "count", aes(fill = cntry)) +
  scale_y_continuous(labels = scales::percent) +
 scale_x_continuous(breaks = seq(0,10),
 labels = c("kein Vertrauen",
 "1", "2", "3", "4", "5", "6", "7", "8", "9",
 "komplettes Vertrauen"))+
  labs(x = "Vertrauen in nationales Parlament", y = "Prozentuale Häufigkeit")+
  theme_bw()
g3

ggplotly()
ggsave(filename = "Landesparlament_nach_Ländern_2.png", plot = g3, width = 8, height  = 7, dpi = 600)

#Density-Plot 
g4 <- ggplot(data = df.na, aes(x = trstprl, y = after_stat(count)/sum(after_stat(count)), fill = cntry)) +
  geom_density( aes(x = trstprl, fill = cntry))+
  scale_y_continuous(labels = scales::percent) +
 scale_x_continuous(breaks = seq(0,10),
 labels = c("kein Vertrauen",
 "1", "2", "3", "4", "5", "6", "7", "8", "9",
 "komplettes Vertrauen"))+
  labs(x = "Vertrauen auf internationaler Ebene (UN)", y = "Prozentuale Häufigkeit")+
  theme_minimal()
g4

ggplotly()
ggsave(filename = "Landesparlament_nach_Ländern_density.png", plot = g4, width = 8, height  = 7, dpi = 600)

3.2 Vertrauen auf supranationaler Ebene

prozentuale Verteilung des Vertraunes und Aufteilung nach den verschiedenen Ländern

#Kolmogorov-Smirnoff-Test
ks.test(df.na$trstep, "pnorm", mean = mean(df.na$trstep), sd = sd(df.na$trstep))
## Warning in ks.test.default(df.na$trstep, "pnorm", mean = mean(df.na$trstep), :
## ties should not be present for the Kolmogorov-Smirnov test
## 
##  Asymptotic one-sample Kolmogorov-Smirnov test
## 
## data:  df.na$trstep
## D = 0.13602, p-value < 2.2e-16
## alternative hypothesis: two-sided
DescTools::Desc(df.na$trstep)
## ------------------------------------------------------------------------------ 
## df.na$trstep (numeric)
## 
##   length       n    NAs  unique     0s   mean  meanCI'
##   41'542  41'542      0      11  4'547   4.47    4.45
##           100.0%   0.0%          10.9%           4.50
##                                                      
##      .05     .10    .25  median    .75    .90     .95
##     0.00    0.00   3.00    5.00   6.00   8.00    8.00
##                                                      
##    range      sd  vcoef     mad    IQR   skew    kurt
##    10.00    2.58   0.58    2.97   3.00  -0.15   -0.75
##                                                      
## 
##     value   freq   perc  cumfreq  cumperc
## 1       0  4'547  10.9%    4'547    10.9%
## 2       1  2'227   5.4%    6'774    16.3%
## 3       2  3'313   8.0%   10'087    24.3%
## 4       3  4'111   9.9%   14'198    34.2%
## 5       4  4'302  10.4%   18'500    44.5%
## 6       5  8'053  19.4%   26'553    63.9%
## 7       6  5'340  12.9%   31'893    76.8%
## 8       7  4'738  11.4%   36'631    88.2%
## 9       8  3'084   7.4%   39'715    95.6%
## 10      9  1'091   2.6%   40'806    98.2%
## 11     10    736   1.8%   41'542   100.0%
## 
## ' 95%-CI (classic)

#Vertrauen auf supranationaler Ebene 
g5 <- ggplot(df.na, aes( trstep)) +
 geom_bar(aes(y = after_stat(count)/sum(after_stat(count))),
 fill = "brown", color = "lightblue")+
 scale_y_continuous(labels = scales::percent) +
 scale_x_continuous(breaks = seq(0,10),
 labels = c("kein Vertrauen",
 "1", "2", "3", "4", "5", "6", "7", "8", "9",
 "komplettes Vertrauen"))+
 labs(title = "Vertrauen auf Supranationaler Ebene (Europarl.)",
 caption = "Data: ESS9",
 y = "Häufigkeit in Prozent",
 x ="Vertrauen in Europaparlament")+
 theme_bw()
g5

ggsave(filename = "Europaparlament.png", plot = g5, width = 8, height  = 7, dpi = 600)

#Aufteilung nach Ländern
g6 <- ggplot(df.na, aes( trstep)) +
 geom_bar(aes(y = after_stat(count)/sum(after_stat(count))),
 fill = "brown", color = "lightblue")+
 scale_y_continuous(labels = scales::percent) +
 labs(title = "Vertrauen in Europäisches Parlament",
 caption = "Data: ESS9",
 y = "Häufigkeit in Prozent",
 x ="Vertrauen in Europäisches Parlament")+
 theme_bw()+
facet_grid(~cntry)
g6

ggplotly()
ggsave(filename = "Europaparlament_nach_Länder.png", plot = g6, width = 12, height  = 5, dpi = 600)

g7 <- ggplot(data = df.na, aes(x = trstep, y = after_stat(count)/sum(after_stat(count)))) +
  geom_bar(stat = "count", aes(fill = cntry)) +
  scale_y_continuous(labels = scales::percent) +
 scale_x_continuous(breaks = seq(0,10),
 labels = c("kein Vertrauen",
 "1", "2", "3", "4", "5", "6", "7", "8", "9",
 "komplettes Vertrauen"))+
  labs(x = "Vertrauen auf Supranationaler Ebene (Europarl.)", y = "Prozentuale Häufigkeit")+
  theme_bw()
g7

ggplotly()
ggsave(filename = "Europaparlament_nach_Länder_2.png", plot = g7, width = 8, height  = 7, dpi = 600)

#Density-Plot 
g8 <- ggplot(data = df.na, aes(x = trstep, y = after_stat(count)/sum(after_stat(count)), fill = cntry)) +
  geom_density( aes(x = trstep, fill = cntry))+
  scale_y_continuous(labels = scales::percent) +
 scale_x_continuous(breaks = seq(0,10),
 labels = c("kein Vertrauen",
 "1", "2", "3", "4", "5", "6", "7", "8", "9",
 "komplettes Vertrauen"))+
  labs(x = "Vertrauen in europäisches Parlament", y = "Prozentuale Häufigkeit")+
  theme_minimal()
g8

ggplotly()
ggsave(filename = "Europaparlament_density.png", plot = g8, width = 8, height  = 7, dpi = 600)

3.3 Vertrauen auf internationale Ebene

#Kolmogorov-Smirnoff-Test
ks.test(df.na$trstun, "pnorm", mean = mean(df.na$trstun), sd = sd(df.na$trstun))
## Warning in ks.test.default(df.na$trstun, "pnorm", mean = mean(df.na$trstun), :
## ties should not be present for the Kolmogorov-Smirnov test
## 
##  Asymptotic one-sample Kolmogorov-Smirnov test
## 
## data:  df.na$trstun
## D = 0.13411, p-value < 2.2e-16
## alternative hypothesis: two-sided
DescTools::Desc(df.na$trstun)
## ------------------------------------------------------------------------------ 
## df.na$trstun (numeric)
## 
##   length       n    NAs  unique     0s   mean  meanCI'
##   41'542  41'542      0      11  3'466   5.08    5.05
##           100.0%   0.0%           8.3%           5.10
##                                                      
##      .05     .10    .25  median    .75    .90     .95
##     0.00    1.00   3.00    5.00   7.00   8.00    9.00
##                                                      
##    range      sd  vcoef     mad    IQR   skew    kurt
##    10.00    2.63   0.52    2.97   4.00  -0.33   -0.64
##                                                      
## 
##     value   freq   perc  cumfreq  cumperc
## 1       0  3'466   8.3%    3'466     8.3%
## 2       1  1'659   4.0%    5'125    12.3%
## 3       2  2'635   6.3%    7'760    18.7%
## 4       3  3'293   7.9%   11'053    26.6%
## 5       4  3'657   8.8%   14'710    35.4%
## 6       5  7'660  18.4%   22'370    53.8%
## 7       6  5'407  13.0%   27'777    66.9%
## 8       7  5'812  14.0%   33'589    80.9%
## 9       8  4'760  11.5%   38'349    92.3%
## 10      9  1'933   4.7%   40'282    97.0%
## 11     10  1'260   3.0%   41'542   100.0%
## 
## ' 95%-CI (classic)

#Vertrauen auf internationaler Ebene 

g9 <- ggplot(df.na, aes( trstun)) +
 geom_bar(aes(y = after_stat(count)/sum(after_stat(count))),
 fill = "brown", color = "lightblue")+
 scale_y_continuous(labels = scales::percent) +
 scale_x_continuous(breaks = seq(0,10),
 labels = c("kein Vertrauen",
 "1", "2", "3", "4", "5", "6", "7", "8", "9",
 "komplettes Vertrauen"))+
 labs(title = "Vertrauen auf internationaler Ebene (UN)",
 caption = "Data: ESS9",
 y = "Häufigkeit in Prozent",
 x ="Vertrauen in UN")+
 theme_bw()
g9

ggsave(filename = "UN.png", plot = g9, width = 8, height  = 7, dpi = 600)

#Aufteilung nach Ländern
g10 <- ggplot(df.na, aes( trstun)) +
 geom_bar(aes(y = after_stat(count)/sum(after_stat(count))),
 fill = "brown", color = "lightblue")+
 scale_y_continuous(labels = scales::percent) +
 labs(title = "Vertrauen auf internationaler Ebene (UN)",
 caption = "Data: ESS9",
 y = "Häufigkeit in Prozent",
 x ="Vertrauen in UN")+
 theme_bw()+
facet_grid(~cntry)
g10

ggplotly()
ggsave(filename = "UN_nach_Länder.png", plot = g10, width = 12, height  = 5, dpi = 600)

g11 <- ggplot(data = df.na, aes(x = trstun, y = after_stat(count)/sum(after_stat(count)))) +
  geom_bar(stat = "count", aes(fill = cntry)) +
  scale_y_continuous(labels = scales::percent) +
 scale_x_continuous(breaks = seq(0,10),
 labels = c("kein Vertrauen",
 "1", "2", "3", "4", "5", "6", "7", "8", "9",
 "komplettes Vertrauen"))+
  labs(x = "Vertrauen auf internationaler Ebene (UN)", y = "Prozentuale Häufigkeit")+
  theme_minimal()
g11

ggplotly()
ggsave(filename = "UN_nach_Länder_.png", plot = g11, width = 8, height  = 7, dpi = 600)

#Density-Plot 
g12 <- ggplot(data = df.na, aes(x = trstun, y = after_stat(count)/sum(after_stat(count)), fill = cntry)) +
  geom_density( aes(x = trstun, fill = cntry))+
  scale_y_continuous(labels = scales::percent) +
 scale_x_continuous(breaks = seq(0,10),
 labels = c("kein Vertrauen",
 "1", "2", "3", "4", "5", "6", "7", "8", "9",
 "komplettes Vertrauen"))+
  labs(x = "Vertrauen auf internationaler Ebene (UN)", y = "Prozentuale Häufigkeit")+
  theme_minimal()
g12

ggplotly()
ggsave(filename = "UN_density.png", plot = g12, width = 8, height  = 7, dpi = 600)

3.4 Deskriptive Beschreibung

sumtable(df.na, vars = c('trstprl', 'trstep', 'trstun'),
         summ = list( c('notNA(x)', 'mean(x)', 'median(x)', 'sd(x)', 'min(x)', 'max(x)', 'pctile(x)[25]',  'pctile(x)[75]')
                      ),
        summ.names = list(
          c('N', 'Mean', 'Median', 'Standard Error', 'Minimum', 'Maximum', '1 Quantil', '4 Quantil')
          )
          , title = "Deskripitive Statistik"
          , labels = c("Vertrauen in nationales Parlament", "Vertrauen in Europäisches Parlament", "Vertrauen in UN"), 
         file = 'Deskriptive Statistik Kontrollvariablen')
Deskripitive Statistik
Variable N Mean Median Standard Error Minimum Maximum 1 Quantil 4 Quantil
Vertrauen in nationales Parlament 41542 4.504 5 2.65 0 10 3 7
Vertrauen in Europäisches Parlament 41542 4.471 5 2.578 0 10 3 6
Vertrauen in UN 41542 5.078 5 2.63 0 10 3 7

3.5 Vergleich durchschnittliches Vertrauen zwischen den Ländern

Es wird zuerst überprüft, ob es Extrempunkte gibt in der Verteilung und dann der Mean berechnet für das durchschnittliche Vertrauen in die drei Institutionen und dann über alle Länder miteinader verglichen.

#Means für alle Länder berechnen zum Vertrauen ins Parlament 
mean(df.na$trstprl[df.na$cntry == "AT"]) #Österreich 
## [1] 5.442544
mean(df.na$trstprl[df.na$cntry == "BE"]) #Belgien 
## [1] 4.80472
mean(df.na$trstprl[df.na$cntry == "BG"]) #Bulgarien 
## [1] 2.487334
mean(df.na$trstprl[df.na$cntry == "CH"]) #Schweiz 
## [1] 6.395865
mean(df.na$trstprl[df.na$cntry == "CY"]) #Zypern 
## [1] 3.667638
mean(df.na$trstprl[df.na$cntry == "CZ"]) #Tschechien 
## [1] 4.22248
mean(df.na$trstprl[df.na$cntry == "DE"]) #Deutschland 
## [1] 5.129003
mean(df.na$trstprl[df.na$cntry == "DK"]) #Dänemark 
## [1] NaN
mean(df.na$trstprl[df.na$cntry == "EE"]) #Estland 
## [1] 4.886957
mean(df.na$trstprl[df.na$cntry == "ES"]) #Spanien 
## [1] 4.14194
mean(df.na$trstprl[df.na$cntry == "FI"]) #Finnland 
## [1] 5.966887
mean(df.na$trstprl[df.na$cntry == "FR"]) #Frankreich 
## [1] 4.14859
mean(df.na$trstprl[df.na$cntry == "GB"]) #Großbritannien 
## [1] 4.243939
mean(df.na$trstprl[df.na$cntry == "HR"]) #Kroatien 
## [1] 2.28153
mean(df.na$trstprl[df.na$cntry == "HU"]) #Ungarn 
## [1] 4.505732
mean(df.na$trstprl[df.na$cntry == "IE"]) #Irland 
## [1] 4.655937
mean(df.na$trstprl[df.na$cntry == "IS"]) #Island 
## [1] NaN
mean(df.na$trstprl[df.na$cntry == "IT"]) #Italien 
## [1] 4.313427
mean(df.na$trstprl[df.na$cntry == "LT"]) #Litauen 
## [1] 3.40852
mean(df.na$trstprl[df.na$cntry == "LV"]) #Lettland 
## [1] 3.364286
mean(df.na$trstprl[df.na$cntry == "ME"]) #Montenegro 
## [1] 4.155515
mean(df.na$trstprl[df.na$cntry == "NL"]) #Niederlande 
## [1] 5.959398
mean(df.na$trstprl[df.na$cntry == "NO"]) #Norwegen 
## [1] 6.836572
mean(df.na$trstprl[df.na$cntry == "PL"]) #Polen 
## [1] 3.860876
mean(df.na$trstprl[df.na$cntry == "PT"]) #Portugal 
## [1] 4.24026
mean(df.na$trstprl[df.na$cntry == "RS"]) #Serbien 
## [1] 3.862699
mean(df.na$trstprl[df.na$cntry == "SE"]) #Schweden 
## [1] 6.224286
mean(df.na$trstprl[df.na$cntry == "SI"]) #Slovenien 
## [1] 3.583048
mean(df.na$trstprl[df.na$cntry == "SK"]) #Slovakei 
## [1] 3.736381

3.5.1 Landesparlament

#Means für alle Länder zum Vertrauen ins Landesparlament (alphabetisch)
mean_df_parl <- as.data.frame(base::tapply(df.na$trstprl, df.na$cntry, FUN = mean, na.rm = T))
tableHTML::tableHTML(mean_df_parl)
base::tapply(df.na$trstprl, df.na$cntry, FUN = mean, na.rm = T)
AT 5.44254385964912
BE 4.8047197640118
BG 2.48733413751508
CH 6.395865237366
CY 3.66763848396501
CZ 4.22248026010218
DE 5.12900315741994
EE 4.88695652173913
ES 4.14194008559201
FI 5.96688741721854
FR 4.14859002169197
GB 4.24393864423553
HR 2.28153018529587
HU 4.50573162508429
IE 4.65593667546174
IT 4.31342668863262
LT 3.40851955307263
LV 3.36428571428571
ME 4.15551537070524
NL 5.95939751146038
NO 6.83657243816254
PL 3.8608762490392
PT 4.24025974025974
RS 3.86269888037714
SE 6.22428571428572
SI 3.58304794520548
SK 3.7363813229572
#Sortiert nach Größe aufsteigend 
df_sorted_parl <- as.data.frame(sort(base::tapply(df.na$trstprl, df.na$cntry, FUN = mean, na.rm = T)))
tableHTML::tableHTML(df_sorted_parl, caption = 'Durchschnittliches Vertrauen in nationale Parlamente')
Durchschnittliches Vertrauen in nationale Parlamente
sort(base::tapply(df.na$trstprl, df.na$cntry, FUN = mean, na.rm = T))
HR 2.28153018529587
BG 2.48733413751508
LV 3.36428571428571
LT 3.40851955307263
SI 3.58304794520548
CY 3.66763848396501
SK 3.7363813229572
PL 3.8608762490392
RS 3.86269888037714
ES 4.14194008559201
FR 4.14859002169197
ME 4.15551537070524
CZ 4.22248026010218
PT 4.24025974025974
GB 4.24393864423553
IT 4.31342668863262
HU 4.50573162508429
IE 4.65593667546174
BE 4.8047197640118
EE 4.88695652173913
DE 5.12900315741994
AT 5.44254385964912
NL 5.95939751146038
FI 5.96688741721854
SE 6.22428571428572
CH 6.395865237366
NO 6.83657243816254

3.5.2 Europäisches Parlament

#Means für alle Länder berechnen zum Vertrauen ins europäische Parlament (alphabetisch)
mean_df_eu <- as.data.frame(base::tapply(df.na$trstep, df.na$cntry, FUN = mean, na.rm = T))
tableHTML::tableHTML(mean_df_eu)
base::tapply(df.na$trstep, df.na$cntry, FUN = mean, na.rm = T)
AT 4.4719298245614
BE 4.89321533923304
BG 3.28407720144752
CH 4.76952526799387
CY 4.65014577259475
CZ 4.13098002786809
DE 4.58592692828146
EE 4.65623188405797
ES 4.51711840228245
FI 5.43226971703793
FR 3.94902386117137
GB 3.41662543295398
HR 3.86491332934848
HU 5.09979770734997
IE 4.9730870712401
IT 4.40444810543657
LT 4.95810055865922
LV 4.34571428571429
ME 4.8001808318264
NL 5.28945645055665
NO 5.45583038869258
PL 4.72636433512683
PT 4.59307359307359
RS 3.07542722451385
SE 5.14285714285714
SI 3.82020547945205
SK 4.47568093385214
#Sortiert nach Größe aufsteigend 
df_sorted_eu <- as.data.frame(sort(base::tapply(df.na$trstep, df.na$cntry, FUN = mean, na.rm = T)))
tableHTML::tableHTML(df_sorted_eu, caption = 'Durchschnittliches Vertrauen ins Europaparlament')
Durchschnittliches Vertrauen ins Europaparlament
sort(base::tapply(df.na$trstep, df.na$cntry, FUN = mean, na.rm = T))
RS 3.07542722451385
BG 3.28407720144752
GB 3.41662543295398
SI 3.82020547945205
HR 3.86491332934848
FR 3.94902386117137
CZ 4.13098002786809
LV 4.34571428571429
IT 4.40444810543657
AT 4.4719298245614
SK 4.47568093385214
ES 4.51711840228245
DE 4.58592692828146
PT 4.59307359307359
CY 4.65014577259475
EE 4.65623188405797
PL 4.72636433512683
CH 4.76952526799387
ME 4.8001808318264
BE 4.89321533923304
LT 4.95810055865922
IE 4.9730870712401
HU 5.09979770734997
SE 5.14285714285714
NL 5.28945645055665
FI 5.43226971703793
NO 5.45583038869258

3.5.3 UN

#Means für alle Länder berechen zum Vertrauen in UN (alphabetisch)
mean_df_un <- as.data.frame(base::tapply(df.na$trstun, df.na$cntry, FUN = mean, na.rm = T))
tableHTML::tableHTML(mean_df_un)
base::tapply(df.na$trstun, df.na$cntry, FUN = mean, na.rm = T)
AT 4.86622807017544
BE 5.28436578171091
BG 3.31604342581424
CH 5.37442572741194
CY 4.62390670553936
CZ 4.79656293543892
DE 4.92106450157871
EE 4.94608695652174
ES 5.00713266761769
FI 6.52317880794702
FR 4.95119305856833
GB 5.05442850074221
HR 4.27854154213987
HU 5.645987862441
IE 5.53720316622691
IT 4.84349258649094
LT 5.0872905027933
LV 4.73571428571428
ME 4.97106690777577
NL 5.94826457105435
NO 6.96113074204947
PL 5.47809377401998
PT 5.63528138528138
RS 3.49145550972304
SE 6.30642857142857
SI 4.41952054794521
SK 4.99416342412451
#Sortiert nach Größe aufsteigend 
df_sorted_un <- as.data.frame(sort(base::tapply(df.na$trstun, df.na$cntry, FUN = mean, na.rm = T)))
tableHTML::tableHTML(df_sorted_un, caption = 'Durchschnittliches Vertrauen in die UN')
Durchschnittliches Vertrauen in die UN
sort(base::tapply(df.na$trstun, df.na$cntry, FUN = mean, na.rm = T))
BG 3.31604342581424
RS 3.49145550972304
HR 4.27854154213987
SI 4.41952054794521
CY 4.62390670553936
LV 4.73571428571428
CZ 4.79656293543892
IT 4.84349258649094
AT 4.86622807017544
DE 4.92106450157871
EE 4.94608695652174
FR 4.95119305856833
ME 4.97106690777577
SK 4.99416342412451
ES 5.00713266761769
GB 5.05442850074221
LT 5.0872905027933
BE 5.28436578171091
CH 5.37442572741194
PL 5.47809377401998
IE 5.53720316622691
PT 5.63528138528138
HU 5.645987862441
NL 5.94826457105435
SE 6.30642857142857
FI 6.52317880794702
NO 6.96113074204947

3.5.4 Grafik

#Durchschnitt Vertrauen Parlament 
mean_parl <- mean(df.na$trstprl, na.rm = T)
DescTools::Desc(df.na$trstprl)
## ------------------------------------------------------------------------------ 
## df.na$trstprl (numeric)
## 
##   length       n    NAs  unique     0s   mean  meanCI'
##   41'542  41'542      0      11  4'645   4.50    4.48
##           100.0%   0.0%          11.2%           4.53
##                                                      
##      .05     .10    .25  median    .75    .90     .95
##     0.00    0.00   3.00    5.00   7.00   8.00    9.00
##                                                      
##    range      sd  vcoef     mad    IQR   skew    kurt
##    10.00    2.65   0.59    2.97   4.00  -0.11   -0.82
##                                                      
## 
##     value   freq   perc  cumfreq  cumperc
## 1       0  4'645  11.2%    4'645    11.2%
## 2       1  2'200   5.3%    6'845    16.5%
## 3       2  3'375   8.1%   10'220    24.6%
## 4       3  4'471  10.8%   14'691    35.4%
## 5       4  4'161  10.0%   18'852    45.4%
## 6       5  7'258  17.5%   26'110    62.9%
## 7       6  4'870  11.7%   30'980    74.6%
## 8       7  4'979  12.0%   35'959    86.6%
## 9       8  3'474   8.4%   39'433    94.9%
## 10      9  1'167   2.8%   40'600    97.7%
## 11     10    942   2.3%   41'542   100.0%
## 
## ' 95%-CI (classic)

#Durchschnitt Vertrauen Europa 
mean_eu <- mean(df.na$trstep, na.rm = T)
DescTools::Desc(df.na$trstep)
## ------------------------------------------------------------------------------ 
## df.na$trstep (numeric)
## 
##   length       n    NAs  unique     0s   mean  meanCI'
##   41'542  41'542      0      11  4'547   4.47    4.45
##           100.0%   0.0%          10.9%           4.50
##                                                      
##      .05     .10    .25  median    .75    .90     .95
##     0.00    0.00   3.00    5.00   6.00   8.00    8.00
##                                                      
##    range      sd  vcoef     mad    IQR   skew    kurt
##    10.00    2.58   0.58    2.97   3.00  -0.15   -0.75
##                                                      
## 
##     value   freq   perc  cumfreq  cumperc
## 1       0  4'547  10.9%    4'547    10.9%
## 2       1  2'227   5.4%    6'774    16.3%
## 3       2  3'313   8.0%   10'087    24.3%
## 4       3  4'111   9.9%   14'198    34.2%
## 5       4  4'302  10.4%   18'500    44.5%
## 6       5  8'053  19.4%   26'553    63.9%
## 7       6  5'340  12.9%   31'893    76.8%
## 8       7  4'738  11.4%   36'631    88.2%
## 9       8  3'084   7.4%   39'715    95.6%
## 10      9  1'091   2.6%   40'806    98.2%
## 11     10    736   1.8%   41'542   100.0%
## 
## ' 95%-CI (classic)

#Durchschnitt Vertrauen UN 
mean_un <- mean(df.na$trstun, na.rm = T)
DescTools::Desc(df.na$trstun)
## ------------------------------------------------------------------------------ 
## df.na$trstun (numeric)
## 
##   length       n    NAs  unique     0s   mean  meanCI'
##   41'542  41'542      0      11  3'466   5.08    5.05
##           100.0%   0.0%           8.3%           5.10
##                                                      
##      .05     .10    .25  median    .75    .90     .95
##     0.00    1.00   3.00    5.00   7.00   8.00    9.00
##                                                      
##    range      sd  vcoef     mad    IQR   skew    kurt
##    10.00    2.63   0.52    2.97   4.00  -0.33   -0.64
##                                                      
## 
##     value   freq   perc  cumfreq  cumperc
## 1       0  3'466   8.3%    3'466     8.3%
## 2       1  1'659   4.0%    5'125    12.3%
## 3       2  2'635   6.3%    7'760    18.7%
## 4       3  3'293   7.9%   11'053    26.6%
## 5       4  3'657   8.8%   14'710    35.4%
## 6       5  7'660  18.4%   22'370    53.8%
## 7       6  5'407  13.0%   27'777    66.9%
## 8       7  5'812  14.0%   33'589    80.9%
## 9       8  4'760  11.5%   38'349    92.3%
## 10      9  1'933   4.7%   40'282    97.0%
## 11     10  1'260   3.0%   41'542   100.0%
## 
## ' 95%-CI (classic)

#Grafische Darstellung 
#Dataframe aus den Mittelwerten 
var_mean <- c(mean_parl, mean_eu, mean_un)
skala <- c("Landesparlament","Europäisches Parlament","Vereinte Nationen")
df1 <- data.frame(var_mean, skala)
df1
##   var_mean                  skala
## 1 4.503515        Landesparlament
## 2 4.470560 Europäisches Parlament
## 3 5.077729      Vereinte Nationen
library(forcats)
Grafik <-df1 %>%
  mutate(skala = fct_reorder(skala, var_mean)) %>%
  ggplot(aes(x= var_mean, y = skala)) +
  geom_point(size = 2, show.legend = T,)+
  xlab("Durchschnittliches Vertrauen")+
  ylab("Politische Instiutionen")+
  ggtitle("Durchschnittliches Vertrauen in verschiedene politische Institutionen")+
  geom_line()
Grafik
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?

ggsave(filename = "Vertrauenslevel.png", plot = Grafik, width = 8, height  = 7, dpi = 1000)
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?

4. Datensätze für Vergleich in Heatmap

Die bereits aufbereiteten Variablen werden genutzt. Die Means der Länder werden miteinander in Vergleich gesetzt.

4.1 Nationales Parlament

#Daten für Vertrauen in nationales Parlament
df = data.frame(
  col1 = c('AT','BE','BG','CH','CY','CZ','DE','EE','ES','FI','FR','HR','HU','IE','IT','LT','LV','ME','NL','NO','PL','PT','RS','SE','SI','SK','UK'),
  col2 = c(5.44254385964912,4.8047197640118,2.48733413751508,6.395865237366,3.66763848396501,4.22248026010218,5.12900315741994,4.88695652173913,4.14194008559201,5.96688741721854,4.14859002169197,2.28153018529587,4.50573162508429,4.65593667546174,4.31342668863262,3.40851955307263,3.36428571428571,4.15551537070524,5.95939751146038,6.83657243816254,3.8608762490392,4.24025974025974,3.86269888037714,6.22428571428572,3.58304794520548,3.7363813229572,4.24393864423553
)
  )
names(df)[names(df) == "col1"] <- "geo"
names(df)[names(df) == "col2"] <- "means"
names(df)
## [1] "geo"   "means"
tableHTML::tableHTML(df)
geo means
1 AT 5.44254385964912
2 BE 4.8047197640118
3 BG 2.48733413751508
4 CH 6.395865237366
5 CY 3.66763848396501
6 CZ 4.22248026010218
7 DE 5.12900315741994
8 EE 4.88695652173913
9 ES 4.14194008559201
10 FI 5.96688741721854
11 FR 4.14859002169197
12 HR 2.28153018529587
13 HU 4.50573162508429
14 IE 4.65593667546174
15 IT 4.31342668863262
16 LT 3.40851955307263
17 LV 3.36428571428571
18 ME 4.15551537070524
19 NL 5.95939751146038
20 NO 6.83657243816254
21 PL 3.8608762490392
22 PT 4.24025974025974
23 RS 3.86269888037714
24 SE 6.22428571428572
25 SI 3.58304794520548
26 SK 3.7363813229572
27 UK 4.24393864423553

4.2 Europäisches Parlament

#Daten für Vertrauen in europäisches Parlament
df.1 = data.frame(
  col1 = c('AT','BE','BG','CH','CY','CZ','DE','EE','ES','FI','FR','HR','HU','IE','IT','LT','LV','ME','NL','NO','PL','PT','RS','SE','SI','SK','UK'),
  col2 = c(4.4719298245614,4.89321533923304,3.28407720144752,4.76952526799387,4.65014577259475,4.13098002786809,4.58592692828146,4.65623188405797,4.51711840228245,5.43226971703793,3.94902386117137,3.86491332934848,5.09979770734997,4.9730870712401
,4.40444810543657,4.95810055865922,4.34571428571429,4.8001808318264,5.28945645055665,5.45583038869258,4.72636433512683,4.59307359307359,3.07542722451385,5.14285714285714,3.82020547945205,4.47568093385214,3.41662543295398
  )
)
names(df.1)[names(df.1) == "col1"] <- "geo"
names(df.1)[names(df.1) == "col2"] <- "means"
names(df.1)
## [1] "geo"   "means"
tableHTML::tableHTML(df.1)
geo means
1 AT 4.4719298245614
2 BE 4.89321533923304
3 BG 3.28407720144752
4 CH 4.76952526799387
5 CY 4.65014577259475
6 CZ 4.13098002786809
7 DE 4.58592692828146
8 EE 4.65623188405797
9 ES 4.51711840228245
10 FI 5.43226971703793
11 FR 3.94902386117137
12 HR 3.86491332934848
13 HU 5.09979770734997
14 IE 4.9730870712401
15 IT 4.40444810543657
16 LT 4.95810055865922
17 LV 4.34571428571429
18 ME 4.8001808318264
19 NL 5.28945645055665
20 NO 5.45583038869258
21 PL 4.72636433512683
22 PT 4.59307359307359
23 RS 3.07542722451385
24 SE 5.14285714285714
25 SI 3.82020547945205
26 SK 4.47568093385214
27 UK 3.41662543295398

4.3 UN

#Daten für Vertrauen in die UN
df.2 = data.frame(
   col1 = c('AT','BE','BG','CH','CY','CZ','DE','EE','ES','FI','FR','HR','HU','IE','IT','LT','LV','ME','NL','NO','PL','PT','RS','SE','SI','SK','UK'),
   col2 = c(4.86622807017544,5.2843657817109,3.31604342581424,5.37442572741194,4.62390670553936,4.79656293543892,4.92106450157871,4.94608695652174,5.00713266761769,6.52317880794702,4.95119305856833,4.27854154213987,5.645987862441,5.53720316622691,4.84349258649094,5.0872905027933,4.73571428571428,4.97106690777577,5.94826457105435,6.96113074204947,5.47809377401998,5.63528138528138,3.49145550972304,6.30642857142857,4.41952054794521,4.99416342412451,5.05442850074221
   )
)
names(df.2)[names(df.2) == "col1"] <- "geo"
names(df.2)[names(df.2) == "col2"] <- "means"
names(df.2)
## [1] "geo"   "means"
tableHTML::tableHTML(df.2)
geo means
1 AT 4.86622807017544
2 BE 5.2843657817109
3 BG 3.31604342581424
4 CH 5.37442572741194
5 CY 4.62390670553936
6 CZ 4.79656293543892
7 DE 4.92106450157871
8 EE 4.94608695652174
9 ES 5.00713266761769
10 FI 6.52317880794702
11 FR 4.95119305856833
12 HR 4.27854154213987
13 HU 5.645987862441
14 IE 5.53720316622691
15 IT 4.84349258649094
16 LT 5.0872905027933
17 LV 4.73571428571428
18 ME 4.97106690777577
19 NL 5.94826457105435
20 NO 6.96113074204947
21 PL 5.47809377401998
22 PT 5.63528138528138
23 RS 3.49145550972304
24 SE 6.30642857142857
25 SI 4.41952054794521
26 SK 4.99416342412451
27 UK 5.05442850074221

4.4 Mergen der Länderdaten

4.4.1 nationale Parlamente

library(eurostat)
library(leaflet)
library(sf)
## Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(scales)
## 
## Attaching package: 'scales'
## The following object is masked from 'package:datawizard':
## 
##     rescale
## The following objects are masked from 'package:psych':
## 
##     alpha, rescale
## The following object is masked from 'package:purrr':
## 
##     discard
## The following object is masked from 'package:readr':
## 
##     col_factor
library(cowplot)
## 
## Attaching package: 'cowplot'
## The following object is masked from 'package:ggpubr':
## 
##     get_legend
## The following objects are masked from 'package:sjPlot':
## 
##     plot_grid, save_plot
## The following object is masked from 'package:patchwork':
## 
##     align_plots
library(ggthemes)
## 
## Attaching package: 'ggthemes'
## The following object is masked from 'package:cowplot':
## 
##     theme_map
#Vertrauen in Landesparlamente
# Get the world map
get_eurostat_geospatial(resolution = 10,
                        nuts_level = 0,
                        year = 2016)
## Object cached at /var/folders/g0/4kzvprs97gg1wbgfmp3lsm780000gn/T//Rtmpznnxj2/eurostat/sf10020164326.RData
## sf at resolution 1: 10  cached at:  /var/folders/g0/4kzvprs97gg1wbgfmp3lsm780000gn/T//Rtmpznnxj2/eurostat/sf10020164326.RData
## Warning in get_eurostat_geospatial(resolution = 10, nuts_level = 0, year =
## 2016): Default of 'make_valid' for 'output_class="sf"' will be changed in the
## future (see function details).
## Simple feature collection with 37 features and 11 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -63.08825 ymin: -21.38917 xmax: 55.83616 ymax: 71.15304
## Geodetic CRS:  WGS 84
## First 10 features:
##    id LEVL_CODE NUTS_ID CNTR_CODE       NAME_LATN       NUTS_NAME MOUNT_TYPE
## 1  AL         0      AL        AL       SHQIPËRIA       SHQIPËRIA          0
## 2  AT         0      AT        AT      ÖSTERREICH      ÖSTERREICH          0
## 3  BE         0      BE        BE BELGIQUE-BELGIË BELGIQUE-BELGIË          0
## 4  NL         0      NL        NL       NEDERLAND       NEDERLAND          0
## 5  PL         0      PL        PL          POLSKA          POLSKA          0
## 6  PT         0      PT        PT        PORTUGAL        PORTUGAL          0
## 7  DK         0      DK        DK         DANMARK         DANMARK          0
## 8  DE         0      DE        DE     DEUTSCHLAND     DEUTSCHLAND          0
## 9  EL         0      EL        EL          ELLADA          ΕΛΛΑΔΑ          0
## 10 ES         0      ES        ES          ESPAÑA          ESPAÑA          0
##    URBN_TYPE COAST_TYPE FID                       geometry geo
## 1          0          0  AL MULTIPOLYGON (((19.82698 42...  AL
## 2          0          0  AT MULTIPOLYGON (((15.54245 48...  AT
## 3          0          0  BE MULTIPOLYGON (((5.10218 51....  BE
## 4          0          0  NL MULTIPOLYGON (((6.87491 53....  NL
## 5          0          0  PL MULTIPOLYGON (((18.95003 54...  PL
## 6          0          0  PT MULTIPOLYGON (((-8.16508 41...  PT
## 7          0          0  DK MULTIPOLYGON (((14.8254 55....  DK
## 8          0          0  DE MULTIPOLYGON (((8.63593 54....  DE
## 9          0          0  EL MULTIPOLYGON (((29.60853 36...  EL
## 10         0          0  ES MULTIPOLYGON (((4.28746 39....  ES
SHP_0 <- get_eurostat_geospatial(resolution = 10,
                                 nuts_level = 0,
                                 year = 2016)
## Object cached at /var/folders/g0/4kzvprs97gg1wbgfmp3lsm780000gn/T//Rtmpznnxj2/eurostat/sf10020164326.RData
## Reading cache file /var/folders/g0/4kzvprs97gg1wbgfmp3lsm780000gn/T//Rtmpznnxj2/eurostat/sf10020164326.RData
## sf at resolution 1: 10  from year  2016  read from cache file:  /var/folders/g0/4kzvprs97gg1wbgfmp3lsm780000gn/T//Rtmpznnxj2/eurostat/sf10020164326.RData
## Warning in get_eurostat_geospatial(resolution = 10, nuts_level = 0, year =
## 2016): Default of 'make_valid' for 'output_class="sf"' will be changed in the
## future (see function details).
#27 EU Länder auswählen 
#EU27 <- eu_countries %>%
  #filter( code == country) %>%
#select(geo = code, name)
#View(EU27)

SHP_27 <- SHP_0 %>% 
  select(geo) %>%
  inner_join(df, by = "geo") %>%
  arrange(geo) %>%
  st_as_sf()

SHP_27 %>% 
  ggplot() +
  geom_sf() +
  scale_x_continuous(limits = c(-10, 35)) +
  scale_y_continuous(limits = c(35, 65)) +
  theme_void()

df_shp <- df %>% 
  select(geo, means) %>%
  inner_join(SHP_27, by = "geo") %>%
  st_as_sf()

4.4.2 EU-Parlament

#Vertrauen in EU-Parlament
# Get the world map
get_eurostat_geospatial(resolution = 10,
                        nuts_level = 0,
                        year = 2016)
## Object cached at /var/folders/g0/4kzvprs97gg1wbgfmp3lsm780000gn/T//Rtmpznnxj2/eurostat/sf10020164326.RData
## Reading cache file /var/folders/g0/4kzvprs97gg1wbgfmp3lsm780000gn/T//Rtmpznnxj2/eurostat/sf10020164326.RData
## sf at resolution 1: 10  from year  2016  read from cache file:  /var/folders/g0/4kzvprs97gg1wbgfmp3lsm780000gn/T//Rtmpznnxj2/eurostat/sf10020164326.RData
## Warning in get_eurostat_geospatial(resolution = 10, nuts_level = 0, year =
## 2016): Default of 'make_valid' for 'output_class="sf"' will be changed in the
## future (see function details).
## Simple feature collection with 37 features and 11 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -63.08825 ymin: -21.38917 xmax: 55.83616 ymax: 71.15304
## Geodetic CRS:  WGS 84
## First 10 features:
##    id LEVL_CODE NUTS_ID CNTR_CODE       NAME_LATN       NUTS_NAME MOUNT_TYPE
## 1  AL         0      AL        AL       SHQIPËRIA       SHQIPËRIA          0
## 2  AT         0      AT        AT      ÖSTERREICH      ÖSTERREICH          0
## 3  BE         0      BE        BE BELGIQUE-BELGIË BELGIQUE-BELGIË          0
## 4  NL         0      NL        NL       NEDERLAND       NEDERLAND          0
## 5  PL         0      PL        PL          POLSKA          POLSKA          0
## 6  PT         0      PT        PT        PORTUGAL        PORTUGAL          0
## 7  DK         0      DK        DK         DANMARK         DANMARK          0
## 8  DE         0      DE        DE     DEUTSCHLAND     DEUTSCHLAND          0
## 9  EL         0      EL        EL          ELLADA          ΕΛΛΑΔΑ          0
## 10 ES         0      ES        ES          ESPAÑA          ESPAÑA          0
##    URBN_TYPE COAST_TYPE FID                       geometry geo
## 1          0          0  AL MULTIPOLYGON (((19.82698 42...  AL
## 2          0          0  AT MULTIPOLYGON (((15.54245 48...  AT
## 3          0          0  BE MULTIPOLYGON (((5.10218 51....  BE
## 4          0          0  NL MULTIPOLYGON (((6.87491 53....  NL
## 5          0          0  PL MULTIPOLYGON (((18.95003 54...  PL
## 6          0          0  PT MULTIPOLYGON (((-8.16508 41...  PT
## 7          0          0  DK MULTIPOLYGON (((14.8254 55....  DK
## 8          0          0  DE MULTIPOLYGON (((8.63593 54....  DE
## 9          0          0  EL MULTIPOLYGON (((29.60853 36...  EL
## 10         0          0  ES MULTIPOLYGON (((4.28746 39....  ES
SHP_1 <- get_eurostat_geospatial(resolution = 10,
                                 nuts_level = 0,
                                 year = 2016)
## Object cached at /var/folders/g0/4kzvprs97gg1wbgfmp3lsm780000gn/T//Rtmpznnxj2/eurostat/sf10020164326.RData
## Reading cache file /var/folders/g0/4kzvprs97gg1wbgfmp3lsm780000gn/T//Rtmpznnxj2/eurostat/sf10020164326.RData
## sf at resolution 1: 10  from year  2016  read from cache file:  /var/folders/g0/4kzvprs97gg1wbgfmp3lsm780000gn/T//Rtmpznnxj2/eurostat/sf10020164326.RData
## Warning in get_eurostat_geospatial(resolution = 10, nuts_level = 0, year =
## 2016): Default of 'make_valid' for 'output_class="sf"' will be changed in the
## future (see function details).
#27 EU Länder auswählen 
#EU27_1 <- eu_countries %>%
#  filter( code == country) %>%
#select(geo = code, name)
#View(EU27)

SHP_27_1 <- SHP_1 %>% 
  select(geo) %>%
  inner_join(df.1, by = "geo") %>%
  arrange(geo) %>%
  st_as_sf()

SHP_27_1 %>% 
  ggplot() +
  geom_sf() +
  scale_x_continuous(limits = c(-10, 35)) +
  scale_y_continuous(limits = c(35, 65)) +
  theme_void()

df_shp_1 <- df.1 %>% 
  select(geo, means) %>%
  inner_join(SHP_27_1, by = "geo") %>%
  st_as_sf()

4.4.3 UN

#Vertrauen in UN
get_eurostat_geospatial(resolution = 10,
                        nuts_level = 0,
                        year = 2016)
## Object cached at /var/folders/g0/4kzvprs97gg1wbgfmp3lsm780000gn/T//Rtmpznnxj2/eurostat/sf10020164326.RData
## Reading cache file /var/folders/g0/4kzvprs97gg1wbgfmp3lsm780000gn/T//Rtmpznnxj2/eurostat/sf10020164326.RData
## sf at resolution 1: 10  from year  2016  read from cache file:  /var/folders/g0/4kzvprs97gg1wbgfmp3lsm780000gn/T//Rtmpznnxj2/eurostat/sf10020164326.RData
## Warning in get_eurostat_geospatial(resolution = 10, nuts_level = 0, year =
## 2016): Default of 'make_valid' for 'output_class="sf"' will be changed in the
## future (see function details).
## Simple feature collection with 37 features and 11 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -63.08825 ymin: -21.38917 xmax: 55.83616 ymax: 71.15304
## Geodetic CRS:  WGS 84
## First 10 features:
##    id LEVL_CODE NUTS_ID CNTR_CODE       NAME_LATN       NUTS_NAME MOUNT_TYPE
## 1  AL         0      AL        AL       SHQIPËRIA       SHQIPËRIA          0
## 2  AT         0      AT        AT      ÖSTERREICH      ÖSTERREICH          0
## 3  BE         0      BE        BE BELGIQUE-BELGIË BELGIQUE-BELGIË          0
## 4  NL         0      NL        NL       NEDERLAND       NEDERLAND          0
## 5  PL         0      PL        PL          POLSKA          POLSKA          0
## 6  PT         0      PT        PT        PORTUGAL        PORTUGAL          0
## 7  DK         0      DK        DK         DANMARK         DANMARK          0
## 8  DE         0      DE        DE     DEUTSCHLAND     DEUTSCHLAND          0
## 9  EL         0      EL        EL          ELLADA          ΕΛΛΑΔΑ          0
## 10 ES         0      ES        ES          ESPAÑA          ESPAÑA          0
##    URBN_TYPE COAST_TYPE FID                       geometry geo
## 1          0          0  AL MULTIPOLYGON (((19.82698 42...  AL
## 2          0          0  AT MULTIPOLYGON (((15.54245 48...  AT
## 3          0          0  BE MULTIPOLYGON (((5.10218 51....  BE
## 4          0          0  NL MULTIPOLYGON (((6.87491 53....  NL
## 5          0          0  PL MULTIPOLYGON (((18.95003 54...  PL
## 6          0          0  PT MULTIPOLYGON (((-8.16508 41...  PT
## 7          0          0  DK MULTIPOLYGON (((14.8254 55....  DK
## 8          0          0  DE MULTIPOLYGON (((8.63593 54....  DE
## 9          0          0  EL MULTIPOLYGON (((29.60853 36...  EL
## 10         0          0  ES MULTIPOLYGON (((4.28746 39....  ES
SHP_2 <- get_eurostat_geospatial(resolution = 10,
                                 nuts_level = 0,
                                 year = 2016)
## Object cached at /var/folders/g0/4kzvprs97gg1wbgfmp3lsm780000gn/T//Rtmpznnxj2/eurostat/sf10020164326.RData
## Reading cache file /var/folders/g0/4kzvprs97gg1wbgfmp3lsm780000gn/T//Rtmpznnxj2/eurostat/sf10020164326.RData
## sf at resolution 1: 10  from year  2016  read from cache file:  /var/folders/g0/4kzvprs97gg1wbgfmp3lsm780000gn/T//Rtmpznnxj2/eurostat/sf10020164326.RData
## Warning in get_eurostat_geospatial(resolution = 10, nuts_level = 0, year =
## 2016): Default of 'make_valid' for 'output_class="sf"' will be changed in the
## future (see function details).
#27 EU Länder auswählen 
#EU27_2 <- eu_countries %>%
 # filter(code == country) %>%
#select(geo = code, name)
#View(EU27)

SHP_27_2 <- SHP_2 %>% 
  select(geo) %>%
  inner_join(df.2, by = "geo") %>%
  arrange(geo) %>%
  st_as_sf()

SHP_27_2 %>% 
  ggplot() +
  geom_sf() +
  scale_x_continuous(limits = c(-10, 35)) +
  scale_y_continuous(limits = c(35, 65)) +
  theme_void()

df_shp_2 <- df.2 %>% 
  select(geo, means) %>%
  inner_join(SHP_27_2, by = "geo") %>%
  st_as_sf()

4.5 Heatmaps

gg_theme <- list(
  theme_void(),
  scale_x_continuous(limits = c(-10, 35)),
  scale_y_continuous(limits = c(36, 70)),
  aes(fill = means.x),
  geom_sf(size = 0.5,
          color = "#F3F3F3"
            ),
  scale_fill_gradient2_tableau(palette = "Red-Blue-White Diverging",
                               breaks = seq(from = 2, to = 7, by = 0.5)),
  labs(subtitle = "Durchschnitt bei einer Skala von 0-10",
       caption = "Data: ESS2019"
       )
)

#ggplot(df_shp,aes(fill = means.x)) +
 # geom_sf(size = 0.5, color = "#F3F3F3") +
  #scale_fill_gradient2_tableau(palette = "Red-Blue-White Diverging", breaks = seq(from = 2, to = 7, by = 0.5)) +
  #scale_x_continuous(limits = c(-10, 35)) +
  #scale_y_continuous(limits = c(36, 70)) +
  #labs(
   # title = "Durchschnittliches Vertrauen in nationales Parlament",
    #subtitle = "Durchschnitt bei einer Skala von 0-10",
    #caption = "Data: ESS2019"
  #) +
  #theme_void()

Es werden Heatmaps von Europa erstellt, wo das durchschnittliche Vertrauen in die jeweilige Institution dargestellt wird

4.5.1 nationale Parlamente

#Durchschnittliches Vertrauen in Landesparlamente
g13  <- df_shp %>%
  ggplot() +
  labs(title = "Durchschnittliches Vertrauen in nationales Parlament") +
  gg_theme
g13

ggplotly()
ggsave(filename = "Heatmap_Land.png", plot = g13, width = 8, height  = 7, dpi = 600)

4.5.2 Europäisches Parlament

#Durchscnittliches Vertrauen in EU-Parlament
g14 <- df_shp_1 %>%
  ggplot() + 
  labs(title = "Durchschnittliches Vertrauen in Europäisches Parlament") +
  gg_theme
g14

ggplotly()
ggsave(filename = "Heatmap_Europa.png", plot = g14, width = 8, height  = 7, dpi = 600)

4.5.3 UN

#Durchschnittliches Vertrauen in die UN
g15 <- df_shp_2 %>%
  ggplot() +
  labs(title = "Durchschnittliches Vertrauen in UN") +
  gg_theme
g15

ggplotly()
ggsave(filename = "Heatmap_UN.png", plot = g15, width = 8, height  = 7, dpi = 600)