1. Tema

Discriminación hacia las mujeres lesbianas en el mercado laboral en México.

2. Planeacion del tema

En el siguiente trabajo, utilicé los datos de la Encuesta Nacional sobre Diversidad Sexual y de Género (ENDISEG) 2021, realizada por el Instituto Nacional de Estadística y Geografía (INEGI), con el fin de conocer aspectos relacionados con las características sexuales, identidad de género y orientación sexual de la población de 15 años y más. A partir de esta encuesta también se abordó la discriminación en los ámbitos laboral y privado, temas que analizaremos a continuación:

3. Explicación de los variables

Variable Pregunta Respuesta
P9_1 Usted se considera 1- hombre, 2- mujer, 3-tanto hombre como mujer, 3-ni hombre, ni mujer, 5-de otro género
P8_1A Usted considera que su orientación es: 1 lesbiana, 2 gay homosexual, 3 bisexual, 4 otra, por ejemplo: pansexual, asexual, b-blanco

Discriminación laboral

Variable Pregunta Respuesta
P11_4_1 Durante los últimos 12 meses, de agosto de 2020 a la fecha, ¿en el trabajo recibió comentarios ofensivos o burlas? 1-Si, 2-No, 3-No aplica, b-blanco
P11_4_2 Durante los últimos 12 meses, de agosto de 2020 a la fecha, ¿en el trabajo le excluyeron de eventos o actividades sociales? 1-Si, 2-No, 3-No aplica, b-blanco
P11_4_3 Durante los últimos 12 meses, de agosto de 2020 a la fecha, ¿en el trabajo le molestaron o acosaron? 1-Si, 2-No, 3-No aplica, b-blanco
P11_4_4 Durante los últimos 12 meses, de agosto de 2020 a la fecha, ¿en el trabajo recibió un trato desigual respecto a los beneficios, prestaciones laborales o ascensos? 1-Si, 2-No, 3-No aplica, b-blanco
P11_4_5 Durante los últimos 12 meses, de agosto de 2020 a la fecha, ¿en el trabajo le pegaron, agredieron o amenazaron? 1-Si, 2-No, 3-No aplica, b-blanco
P11_5_7 En los últimos cinco años, de agosto de 2016 a la fecha, ¿le han negado injustificadamente el empleo o la oportunidad de trabajar? 1-Si, 2-No, 3-No aplica, b-blanco

Discriminación general

Variable Pregunta Respuesta
P11_6_11 En los últimos 12 meses, de agosto de 2020 a la fecha, ¿ha sido discriminada(o), o menospreciada(o), por su preferencia sexual? 1-Si, 2-no, 9-no especificado
P11_8_1 ¿Usted no toma de la mano a su pareja o le muestra su afecto en público por miedo a sufrir agresión o violencia? 1-Si, 2-No se declaró como opción afirmativa
P11_8_2 ¿Usted no toma de la mano a su pareja o le muestra su afecto en público por ser mal visto socialmente? 1-Si, 2-No se declaró como opción afirmativa
P11_8_3 ¿Usted no toma de la mano a su pareja o le muestra su afecto en público por pena o vergüenza? 1-Si, 2-No se declaró como opción afirmativa
P11_8_4 ¿Usted no toma de la mano a su pareja o le muestra su afecto en público por temor a ser discriminada(o)? 1-Si, 2-No se declaró como opción afirmativa
P11_8_5 ¿Usted no toma de la mano a su pareja o le muestra su afecto en público por falta de costumbre? 1-Si, 2-No se declaró como opción afirmativa

Aquí vemos la distribución de la identidad de género.

table(disc_lab$P9_1)
## 
##     1     2     3     4     5 
## 20005 23932   143    47    62
table(disc_lab$P8_1)
## 
##     1     2     3     4     5     6 
##   242   688  1130 22849 19170   110
library(ggplot2)
library(dplyr)

# NA-Werte filtern
disc_lab_filtered <- disc_lab %>% filter(!is.na(P8_1A))

# Diskriminierungslabels erstellen und untereinander anzeigen
labels <- c(
  "1" = "una mujer a la que \n le gustan solamente las mujeres",
  "2" = "un hombre al que \n le gustan solamente los hombres",
  "3" = "una persona que \n le gustan tanto hombres como mujeres",
  "4" = "una mujer que \n le gustan solamente los hombres",
  "5" = "un hombre que \n le gustan solamente las mujeres",
  "6" = "con otra orientación"
)

# Histogramm mit den genauen Zahlenwerten oberhalb der Balken plotten
orientacion_plot <- ggplot(disc_lab_filtered, aes(x = factor(P8_1A, levels = 1:6, labels = labels))) +
  geom_bar(fill = "#760492", color = "white") +
  geom_text(stat = 'count', aes(label = ..count..), vjust = -0.5, color = "black", size = 2.5) +
  labs(
    x = "Orientación Sexual",
    y = "Frecuencia",
    title = "Distribución de la Orientación Sexual",
    title.position = "plot"  # Titelposition außerhalb der Grafik
  ) +
  theme_minimal() +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1),
    plot.margin = unit(c(2, 1, 1, 1), "lines")  # Randvergrößerung oben
  )

# Plot anzeigen
print(orientacion_plot)
## Warning: The dot-dot notation (`..count..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(count)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

ggplot(disc_lab) +
  aes(x = P8_1A) +
  geom_histogram(bins = 30L, fill = "#760492") +
  labs(
    x = "Orientación Sexual",
    y = "Frecuencia",
    title = "Orientación Sexual"
  ) +
  theme_minimal()
## Warning: Removed 42019 rows containing non-finite outside the scale range
## (`stat_bin()`).

table(disc_lab$P8_1A)
## 
##    1    2    3    4 
##  241  599 1107  223
ggplot(disc_lab) +
  aes(x = P9_1) +
  geom_histogram(bins = 30L, fill = "#4682B4") +
  labs(
    x = "Identidad de Género",
    y = "Frecuencia",
    title = "Identidad de Género"
  ) +
  theme_minimal()

table(disc_lab$P9_1)
## 
##     1     2     3     4     5 
## 20005 23932   143    47    62

y de la orientación sexual

table(disc_lab$P8_1)
## 
##     1     2     3     4     5     6 
##   242   688  1130 22849 19170   110

Para considerar más identidades de género y orientación sexual que no sean heterosexuales, la filtración incluye a personas que se consideran mujeres y lesbianas, gays/homosexuales, bisexuales, u otras identidades como pansexuales o asexuales. La filtración es para eliminar a todas las personas que se consideran cis-hombres y heterosexuales.

Depende del grupo, pero en el caso del lesbianismo se entiende que la mayoría son personas que se consideran mujeres, aunque la identificación puede variar entre lesbiana, gay/homosexual, bisexual o pansexual/asexual, es decir, cualquier orientación que no sea heterosexual.

library(dplyr)

# Dummy-Variable 'les' erstellen
disc_lab <- disc_lab %>%
  mutate(les = ifelse(P8_1 %in% c(1, 3, 6), 1, 0))

# Verteilung der Dummy-Variable anzeigen
table(disc_lab$les)
## 
##     0     1 
## 42707  1482
library(dplyr)

# Werte 9 aus den Variablen P11_5_7, P11_6_11 und P11_8_1 entfernen
disc_lab_cleaned <- disc_lab %>%
  mutate(
    P11_5_7 = ifelse(P11_5_7 == 9, NA, P11_5_7),
    P11_6_11 = ifelse(P11_6_11 == 9, NA, P11_6_11),
    P11_8_1 = ifelse(P11_8_1 == 9, NA, P11_8_1)
  )

# Überprüfen der Änderungen
summary(disc_lab_cleaned)
##      FOLIO            VIV_SEL           HOGAR           N_REN       
##  Min.   : 100019   Min.   : 1.000   Min.   :1.000   Min.   : 1.000  
##  1st Qu.: 901874   1st Qu.: 3.000   1st Qu.:1.000   1st Qu.: 1.000  
##  Median :1661245   Median : 4.000   Median :1.000   Median : 2.000  
##  Mean   :1668120   Mean   : 6.735   Mean   :1.012   Mean   : 1.812  
##  3rd Qu.:2460963   3rd Qu.:10.000   3rd Qu.:1.000   3rd Qu.: 2.000  
##  Max.   :3260794   Max.   :37.000   Max.   :5.000   Max.   :14.000  
##                                                                     
##       P4_1           P4_2            P4_3           P4_3A       
##  Min.   :15.0   Min.   :1.000   Min.   :1.000   Min.   : 1.000  
##  1st Qu.:28.0   1st Qu.:2.000   1st Qu.:1.000   1st Qu.: 1.000  
##  Median :41.0   Median :2.000   Median :1.000   Median : 2.000  
##  Mean   :43.2   Mean   :3.212   Mean   :1.089   Mean   : 1.663  
##  3rd Qu.:57.0   3rd Qu.:6.000   3rd Qu.:1.000   3rd Qu.: 2.000  
##  Max.   :98.0   Max.   :6.000   Max.   :2.000   Max.   :17.000  
##                                 NA's   :19686   NA's   :21858   
##       P4_4            P4_5            P4_6           P4_7            P4_8      
##  Min.   :1.000   Min.   :1.00    Min.   :1.00   Min.   :1.000   Min.   :1.000  
##  1st Qu.:2.000   1st Qu.:2.00    1st Qu.:2.00   1st Qu.:1.000   1st Qu.:2.000  
##  Median :2.000   Median :3.00    Median :2.00   Median :2.000   Median :4.000  
##  Mean   :1.973   Mean   :2.49    Mean   :1.93   Mean   :1.797   Mean   :3.172  
##  3rd Qu.:2.000   3rd Qu.:3.00    3rd Qu.:2.00   3rd Qu.:2.000   3rd Qu.:4.000  
##  Max.   :2.000   Max.   :5.00    Max.   :2.00   Max.   :9.000   Max.   :5.000  
##                  NA's   :42999                                  NA's   :29494  
##      P4_9C           PD4_10_1        PD4_10_2        PD4_10_3    
##  Min.   :110101   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:110103   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :110103   Median :1.000   Median :1.000   Median :1.000  
##  Mean   :140491   Mean   :1.272   Mean   :1.352   Mean   :1.119  
##  3rd Qu.:130600   3rd Qu.:1.000   3rd Qu.:2.000   3rd Qu.:1.000  
##  Max.   :999999   Max.   :4.000   Max.   :4.000   Max.   :4.000  
##                                                                  
##     PD4_10_4        PD4_10_5        PD4_10_6        PD4_10_7    
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :1.000   Median :1.000   Median :1.000   Median :1.000  
##  Mean   :1.231   Mean   :1.125   Mean   :1.058   Mean   :1.045  
##  3rd Qu.:1.000   3rd Qu.:1.000   3rd Qu.:1.000   3rd Qu.:1.000  
##  Max.   :4.000   Max.   :4.000   Max.   :4.000   Max.   :4.000  
##                                                                 
##     PD4_10_8         P4_10            NIV              GRA       
##  Min.   :1.000   Min.   :1.000   Min.   : 0.000   Min.   :0.000  
##  1st Qu.:1.000   1st Qu.:2.000   1st Qu.: 2.000   1st Qu.:3.000  
##  Median :1.000   Median :2.000   Median : 3.000   Median :3.000  
##  Mean   :1.073   Mean   :2.515   Mean   : 4.484   Mean   :3.199  
##  3rd Qu.:1.000   3rd Qu.:3.000   3rd Qu.: 6.000   3rd Qu.:4.000  
##  Max.   :4.000   Max.   :6.000   Max.   :10.000   Max.   :6.000  
##                                                                  
##   FILTRO_4_12       P4_12           P4_13           P4_14           P4_15      
##  Min.   :1.00   Min.   :1.00    Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.00   1st Qu.:1.00    1st Qu.:1.000   1st Qu.:6.000   1st Qu.:1.000  
##  Median :2.00   Median :2.00    Median :1.000   Median :6.000   Median :1.000  
##  Mean   :1.73   Mean   :1.69    Mean   :2.849   Mean   :5.504   Mean   :2.434  
##  3rd Qu.:2.00   3rd Qu.:2.00    3rd Qu.:6.000   3rd Qu.:6.000   3rd Qu.:5.000  
##  Max.   :2.00   Max.   :2.00    Max.   :8.000   Max.   :6.000   Max.   :6.000  
##                 NA's   :32276                   NA's   :27300   NA's   :15401  
##      P4_17C         P4_18_1         P4_18_2         P4_18_3     
##  Min.   : 980    Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:3121    1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000  
##  Median :5242    Median :2.000   Median :2.000   Median :2.000  
##  Mean   :5635    Mean   :1.941   Mean   :1.918   Mean   :1.866  
##  3rd Qu.:8199    3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :9999    Max.   :2.000   Max.   :2.000   Max.   :2.000  
##  NA's   :15401                                                  
##     P4_18_4         P4_18_5          P4_19             P5_1       
##  Min.   :1.000   Min.   :1.000   Min.   : 1.000   Min.   : 1.000  
##  1st Qu.:2.000   1st Qu.:2.000   1st Qu.: 6.000   1st Qu.: 5.000  
##  Median :2.000   Median :2.000   Median : 7.000   Median : 6.000  
##  Mean   :1.926   Mean   :1.978   Mean   : 7.239   Mean   : 6.829  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.: 8.000   3rd Qu.: 8.000  
##  Max.   :2.000   Max.   :2.000   Max.   :99.000   Max.   :30.000  
##                                                                   
##      P5_2_1          P5_2_2         P5_2_3          P5_2_4          P5_2_5     
##  Min.   :1.000   Min.   :1.00   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.00   1st Qu.:1.000   1st Qu.:2.000   1st Qu.:2.000  
##  Median :1.000   Median :1.00   Median :1.000   Median :2.000   Median :2.000  
##  Mean   :1.059   Mean   :1.17   Mean   :1.075   Mean   :1.875   Mean   :1.933  
##  3rd Qu.:1.000   3rd Qu.:1.00   3rd Qu.:1.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :9.000   Max.   :9.00   Max.   :9.000   Max.   :9.000   Max.   :9.000  
##                                                                                
##      P5_2_6          P5_2_7         P5_2_8          P5_3_1          P5_3_2     
##  Min.   :1.000   Min.   :1.00   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:2.000   1st Qu.:2.00   1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000  
##  Median :2.000   Median :2.00   Median :2.000   Median :2.000   Median :2.000  
##  Mean   :1.969   Mean   :1.98   Mean   :1.988   Mean   :1.834   Mean   :1.879  
##  3rd Qu.:2.000   3rd Qu.:2.00   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :9.000   Max.   :9.00   Max.   :9.000   Max.   :2.000   Max.   :2.000  
##                                                                                
##      P5_3_3          P5_3_4          P5_4_1          P5_4_2     
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000  
##  Median :2.000   Median :2.000   Median :2.000   Median :2.000  
##  Mean   :1.883   Mean   :1.873   Mean   :1.877   Mean   :1.764  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##                                                                 
##      P5_4_3          P5_4_4          P5_4_5           P7_1      
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000   1st Qu.:1.000  
##  Median :2.000   Median :2.000   Median :2.000   Median :2.000  
##  Mean   :1.852   Mean   :1.925   Mean   :1.828   Mean   :1.545  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##                                                                 
##      P7_1A            P7_2            P7_3           P7_4_1     
##  Min.   :1.000   Min.   : 0.00   Min.   : 0.00   Min.   :1.000  
##  1st Qu.:2.000   1st Qu.:12.00   1st Qu.:14.00   1st Qu.:1.000  
##  Median :2.000   Median :14.00   Median :16.00   Median :1.000  
##  Mean   :2.167   Mean   :13.56   Mean   :15.49   Mean   :1.457  
##  3rd Qu.:2.000   3rd Qu.:15.00   3rd Qu.:18.00   3rd Qu.:2.000  
##  Max.   :9.000   Max.   :99.00   Max.   :99.00   Max.   :2.000  
##                                                  NA's   :2093   
##      P7_4_2          P7_4_3          P7_5           P7_6_1          P7_6_2     
##  Min.   :1.000   Min.   :1      Min.   : 0.00   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:2      1st Qu.:15.00   1st Qu.:1.000   1st Qu.:1.000  
##  Median :2.000   Median :2      Median :18.00   Median :1.000   Median :2.000  
##  Mean   :1.542   Mean   :2      Mean   :17.03   Mean   :1.453   Mean   :1.547  
##  3rd Qu.:2.000   3rd Qu.:2      3rd Qu.:20.00   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2      Max.   :99.00   Max.   :2.000   Max.   :2.000  
##  NA's   :2093    NA's   :2093                   NA's   :3767    NA's   :3767   
##      P7_6_3       FILTRO_7_7         P7_7         FILTRO_7_8         P7_8      
##  Min.   :1      Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:2      1st Qu.:2.000   1st Qu.:4.000   1st Qu.:2.000   1st Qu.:4.000  
##  Median :2      Median :2.000   Median :4.000   Median :2.000   Median :4.000  
##  Mean   :2      Mean   :1.961   Mean   :4.288   Mean   :1.915   Mean   :4.375  
##  3rd Qu.:2      3rd Qu.:2.000   3rd Qu.:5.000   3rd Qu.:2.000   3rd Qu.:5.000  
##  Max.   :2      Max.   :2.000   Max.   :5.000   Max.   :2.000   Max.   :5.000  
##  NA's   :3767                   NA's   :1706                    NA's   :3767   
##       P7_9           P7_10            P7_11            P8_1      
##  Min.   :1.000   Min.   : 1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:4.000   1st Qu.: 1.000   1st Qu.:2.000   1st Qu.:4.000  
##  Median :5.000   Median : 1.000   Median :4.000   Median :4.000  
##  Mean   :4.799   Mean   : 1.768   Mean   :2.984   Mean   :4.366  
##  3rd Qu.:5.000   3rd Qu.: 1.000   3rd Qu.:4.000   3rd Qu.:5.000  
##  Max.   :6.000   Max.   :99.000   Max.   :9.000   Max.   :6.000  
##  NA's   :3767    NA's   :12917    NA's   :12917                  
##      P8_1A          P8_1B                P8_2           P8_3_1     
##  Min.   :1.0     Length:44189       Min.   : 1.0    Min.   :1.00   
##  1st Qu.:2.0     Class :character   1st Qu.: 1.0    1st Qu.:1.00   
##  Median :3.0     Mode  :character   Median :11.0    Median :1.00   
##  Mean   :2.6                        Mean   : 9.6    Mean   :1.43   
##  3rd Qu.:3.0                        3rd Qu.:16.0    3rd Qu.:2.00   
##  Max.   :4.0                        Max.   :98.0    Max.   :2.00   
##  NA's   :42019                      NA's   :42019   NA's   :42019  
##      P8_3_2          P8_3_3          P8_3_4          P8_3_5     
##  Min.   :1.00    Min.   :1.00    Min.   :1.0     Min.   :1.00   
##  1st Qu.:1.00    1st Qu.:1.00    1st Qu.:2.0     1st Qu.:2.00   
##  Median :2.00    Median :2.00    Median :2.0     Median :2.00   
##  Mean   :1.66    Mean   :1.56    Mean   :1.8     Mean   :1.75   
##  3rd Qu.:2.00    3rd Qu.:2.00    3rd Qu.:2.0     3rd Qu.:2.00   
##  Max.   :2.00    Max.   :2.00    Max.   :2.0     Max.   :2.00   
##  NA's   :42019   NA's   :42019   NA's   :42019   NA's   :42019  
##      P8_3_6          P8_3_7          P8_3_8          P8_3_9     
##  Min.   :1.00    Min.   :1.00    Min.   :1.00    Min.   :1.00   
##  1st Qu.:1.00    1st Qu.:2.00    1st Qu.:2.00    1st Qu.:2.00   
##  Median :2.00    Median :2.00    Median :2.00    Median :2.00   
##  Mean   :1.54    Mean   :1.87    Mean   :1.87    Mean   :1.86   
##  3rd Qu.:2.00    3rd Qu.:2.00    3rd Qu.:2.00    3rd Qu.:2.00   
##  Max.   :2.00    Max.   :2.00    Max.   :2.00    Max.   :2.00   
##  NA's   :42019   NA's   :42019   NA's   :42019   NA's   :42019  
##      P8_4_1          P8_4_2          P8_4_3           P8_5      
##  Min.   :1.00    Min.   :1.00    Min.   :1.00    Min.   :1.00   
##  1st Qu.:1.00    1st Qu.:2.00    1st Qu.:2.00    1st Qu.:2.00   
##  Median :1.00    Median :2.00    Median :2.00    Median :2.00   
##  Mean   :1.12    Mean   :1.89    Mean   :1.84    Mean   :2.46   
##  3rd Qu.:1.00    3rd Qu.:2.00    3rd Qu.:2.00    3rd Qu.:2.00   
##  Max.   :2.00    Max.   :2.00    Max.   :2.00    Max.   :9.00   
##  NA's   :42902   NA's   :42902   NA's   :42902   NA's   :42019  
##       P9_1         FILTRO_9_2        P9_2            P9_3           P9_4_1     
##  Min.   :1.000   Min.   :1.00   Min.   : 1.00   Min.   :1.00    Min.   :1.00   
##  1st Qu.:1.000   1st Qu.:2.00   1st Qu.: 1.00   1st Qu.:1.00    1st Qu.:1.00   
##  Median :2.000   Median :2.00   Median : 1.00   Median :2.00    Median :2.00   
##  Mean   :1.557   Mean   :1.99   Mean   : 9.93   Mean   :1.81    Mean   :1.87   
##  3rd Qu.:2.000   3rd Qu.:2.00   3rd Qu.:14.00   3rd Qu.:2.00    3rd Qu.:2.00   
##  Max.   :5.000   Max.   :2.00   Max.   :99.00   Max.   :9.00    Max.   :9.00   
##                                 NA's   :43748   NA's   :43748   NA's   :43748  
##      P9_4_2          P9_4_3          P9_4_4          P9_4_5     
##  Min.   :1.00    Min.   :1.00    Min.   :1.0     Min.   :1.00   
##  1st Qu.:2.00    1st Qu.:1.00    1st Qu.:2.0     1st Qu.:2.00   
##  Median :2.00    Median :2.00    Median :2.0     Median :2.00   
##  Mean   :2.04    Mean   :1.99    Mean   :2.1     Mean   :2.08   
##  3rd Qu.:2.00    3rd Qu.:2.00    3rd Qu.:2.0     3rd Qu.:2.00   
##  Max.   :9.00    Max.   :9.00    Max.   :9.0     Max.   :9.00   
##  NA's   :43748   NA's   :43748   NA's   :43748   NA's   :43748  
##      P9_4_6          P9_4_7          P9_4_8          P9_4_9     
##  Min.   :1.00    Min.   :1.00    Min.   :1.00    Min.   :1.00   
##  1st Qu.:1.00    1st Qu.:2.00    1st Qu.:2.00    1st Qu.:1.00   
##  Median :2.00    Median :2.00    Median :2.00    Median :2.00   
##  Mean   :1.95    Mean   :2.18    Mean   :2.13    Mean   :1.95   
##  3rd Qu.:2.00    3rd Qu.:2.00    3rd Qu.:2.00    3rd Qu.:2.00   
##  Max.   :9.00    Max.   :9.00    Max.   :9.00    Max.   :9.00   
##  NA's   :43748   NA's   :43748   NA's   :43748   NA's   :43748  
##      P9_5_1          P9_5_2          P9_5_3           P9_6      
##  Min.   :1.0     Min.   :1.00    Min.   :1.0     Min.   : 1.00  
##  1st Qu.:1.0     1st Qu.:2.00    1st Qu.:2.0     1st Qu.:16.00  
##  Median :1.0     Median :2.00    Median :2.0     Median :99.00  
##  Mean   :1.2     Mean   :1.84    Mean   :1.8     Mean   :64.32  
##  3rd Qu.:1.0     3rd Qu.:2.00    3rd Qu.:2.0     3rd Qu.:99.00  
##  Max.   :2.0     Max.   :2.00    Max.   :2.0     Max.   :99.00  
##  NA's   :44006   NA's   :44006   NA's   :44006   NA's   :43748  
##       P9_7            P9_8            P9_9           P9_10      
##  Min.   :1.00    Min.   :1.00    Min.   :1.00    Min.   :1.00   
##  1st Qu.:2.00    1st Qu.:1.00    1st Qu.:2.00    1st Qu.:1.00   
##  Median :9.00    Median :1.00    Median :2.00    Median :2.00   
##  Mean   :6.01    Mean   :1.66    Mean   :3.62    Mean   :1.66   
##  3rd Qu.:9.00    3rd Qu.:2.00    3rd Qu.:2.00    3rd Qu.:2.00   
##  Max.   :9.00    Max.   :9.00    Max.   :9.00    Max.   :2.00   
##  NA's   :43748   NA's   :43748   NA's   :43748   NA's   :43748  
##     P9_10A             P10_1_1         P10_1_2         P10_1_3     
##  Length:44189       Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  Class :character   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
##  Mode  :character   Median :2.000   Median :1.000   Median :2.000  
##                     Mean   :1.577   Mean   :1.363   Mean   :1.692  
##                     3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##                     Max.   :2.000   Max.   :2.000   Max.   :2.000  
##                                                                    
##     P10_1_4         P10_1_5          P10_2           P10_3      
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:2.000   1st Qu.:2.000  
##  Median :2.000   Median :2.000   Median :2.000   Median :2.000  
##  Mean   :1.625   Mean   :1.624   Mean   :1.904   Mean   :1.949  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##                                                                 
##   FILTRO_10_4       P10_4_1         P10_4_2         P10_4_3     
##  Min.   :1.000   Min.   :1.0     Min.   :1.00    Min.   :1.00   
##  1st Qu.:1.000   1st Qu.:2.0     1st Qu.:1.00    1st Qu.:2.00   
##  Median :1.000   Median :2.0     Median :1.00    Median :2.00   
##  Mean   :1.108   Mean   :1.8     Mean   :1.37    Mean   :1.82   
##  3rd Qu.:1.000   3rd Qu.:2.0     3rd Qu.:2.00    3rd Qu.:2.00   
##  Max.   :2.000   Max.   :2.0     Max.   :2.00    Max.   :2.00   
##                  NA's   :39423   NA's   :39423   NA's   :39423  
##     P10_4_4         P10_4_5         P10_4_6         P10_4_7     
##  Min.   :1.00    Min.   :1.00    Min.   :1.00    Min.   :1.00   
##  1st Qu.:2.00    1st Qu.:2.00    1st Qu.:2.00    1st Qu.:2.00   
##  Median :2.00    Median :2.00    Median :2.00    Median :2.00   
##  Mean   :1.92    Mean   :1.94    Mean   :1.87    Mean   :2.08   
##  3rd Qu.:2.00    3rd Qu.:2.00    3rd Qu.:2.00    3rd Qu.:2.00   
##  Max.   :2.00    Max.   :2.00    Max.   :9.00    Max.   :9.00   
##  NA's   :39423   NA's   :39423   NA's   :43570   NA's   :44051  
##     P10_4_8       FILTRO_10_5       P10_5_1         P10_5_2     
##  Min.   :1.00    Min.   :1.000   Min.   :1.00    Min.   :1.00   
##  1st Qu.:2.00    1st Qu.:2.000   1st Qu.:2.00    1st Qu.:2.00   
##  Median :2.00    Median :2.000   Median :2.00    Median :2.00   
##  Mean   :1.94    Mean   :1.947   Mean   :1.99    Mean   :1.89   
##  3rd Qu.:2.00    3rd Qu.:2.000   3rd Qu.:2.00    3rd Qu.:2.00   
##  Max.   :2.00    Max.   :2.000   Max.   :9.00    Max.   :9.00   
##  NA's   :39423                   NA's   :41827   NA's   :41827  
##     P10_5_3         P10_5_4         P10_5_5         P10_5_6     
##  Min.   :1.00    Min.   :1.00    Min.   :1.00    Min.   :1      
##  1st Qu.:2.00    1st Qu.:2.00    1st Qu.:2.00    1st Qu.:2      
##  Median :2.00    Median :2.00    Median :2.00    Median :2      
##  Mean   :1.99    Mean   :1.97    Mean   :1.99    Mean   :2      
##  3rd Qu.:2.00    3rd Qu.:2.00    3rd Qu.:2.00    3rd Qu.:2      
##  Max.   :9.00    Max.   :9.00    Max.   :9.00    Max.   :9      
##  NA's   :41827   NA's   :41827   NA's   :41827   NA's   :41827  
##     P10_5_7         P10_6_1         P10_6_2         P10_6_3     
##  Min.   :1.00    Min.   :1.00    Min.   :1.00    Min.   :1.00   
##  1st Qu.:1.00    1st Qu.:2.00    1st Qu.:1.00    1st Qu.:1.00   
##  Median :1.00    Median :2.00    Median :2.00    Median :1.00   
##  Mean   :1.23    Mean   :1.78    Mean   :1.73    Mean   :1.28   
##  3rd Qu.:1.00    3rd Qu.:2.00    3rd Qu.:2.00    3rd Qu.:2.00   
##  Max.   :9.00    Max.   :2.00    Max.   :2.00    Max.   :2.00   
##  NA's   :41827   NA's   :43715   NA's   :43715   NA's   :43715  
##     P10_6_4         P11_1_1        P11_2_1_1       P11_2_1_2    
##  Min.   :1.00    Min.   :1.000   Min.   : 1.00   Min.   : 2.00  
##  1st Qu.:2.00    1st Qu.:2.000   1st Qu.: 3.00   1st Qu.: 5.00  
##  Median :2.00    Median :2.000   Median : 6.00   Median : 6.00  
##  Mean   :1.85    Mean   :1.909   Mean   : 6.08   Mean   : 7.15  
##  3rd Qu.:2.00    3rd Qu.:2.000   3rd Qu.:10.00   3rd Qu.:10.00  
##  Max.   :2.00    Max.   :2.000   Max.   :99.00   Max.   :99.00  
##  NA's   :43715                   NA's   :40162   NA's   :43264  
##    P11_2_1_3        P11_1_2        P11_2_2_1       P11_2_2_2    
##  Min.   : 3.00   Min.   :1.000   Min.   : 1      Min.   : 2.00  
##  1st Qu.: 6.00   1st Qu.:2.000   1st Qu.: 5      1st Qu.: 6.00  
##  Median : 9.00   Median :2.000   Median : 6      Median : 6.00  
##  Mean   : 8.59   Mean   :1.906   Mean   : 7      Mean   : 7.32  
##  3rd Qu.:10.00   3rd Qu.:2.000   3rd Qu.:10      3rd Qu.:10.00  
##  Max.   :99.00   Max.   :2.000   Max.   :10      Max.   :10.00  
##  NA's   :43890                   NA's   :40030   NA's   :43318  
##    P11_2_2_3        P11_1_3        P11_2_3_1       P11_2_3_2    
##  Min.   : 3.00   Min.   :1.000   Min.   : 1.00   Min.   : 2.00  
##  1st Qu.: 6.00   1st Qu.:2.000   1st Qu.: 3.00   1st Qu.: 6.00  
##  Median :10.00   Median :2.000   Median : 6.00   Median : 6.00  
##  Mean   : 8.62   Mean   :1.948   Mean   : 6.38   Mean   : 7.88  
##  3rd Qu.:10.00   3rd Qu.:2.000   3rd Qu.:10.00   3rd Qu.:10.00  
##  Max.   :10.00   Max.   :2.000   Max.   :99.00   Max.   :99.00  
##  NA's   :43889                   NA's   :41885   NA's   :43843  
##    P11_2_3_3        P11_1_4        P11_2_4_1       P11_2_4_2    
##  Min.   : 4.00   Min.   :1.000   Min.   : 1.00   Min.   : 2.00  
##  1st Qu.: 6.00   1st Qu.:1.000   1st Qu.: 3.00   1st Qu.: 5.00  
##  Median :10.00   Median :2.000   Median : 5.00   Median : 6.00  
##  Mean   :10.24   Mean   :1.724   Mean   : 5.48   Mean   : 6.18  
##  3rd Qu.:10.00   3rd Qu.:2.000   3rd Qu.: 7.00   3rd Qu.: 8.00  
##  Max.   :99.00   Max.   :2.000   Max.   :10.00   Max.   :10.00  
##  NA's   :44077                   NA's   :32005   NA's   :39304  
##    P11_2_4_3        P11_1_5        P11_2_5_1       P11_2_5_2    
##  Min.   : 3.00   Min.   :1.000   Min.   : 1.00   Min.   : 2.00  
##  1st Qu.: 6.00   1st Qu.:2.000   1st Qu.: 5.00   1st Qu.: 6.00  
##  Median : 9.00   Median :2.000   Median : 6.00   Median : 6.00  
##  Mean   : 7.79   Mean   :1.814   Mean   : 6.92   Mean   : 6.99  
##  3rd Qu.:10.00   3rd Qu.:2.000   3rd Qu.:10.00   3rd Qu.:10.00  
##  Max.   :10.00   Max.   :2.000   Max.   :10.00   Max.   :10.00  
##  NA's   :41654                   NA's   :35960   NA's   :41868  
##    P11_2_5_3        P11_1_6        P11_2_6_1       P11_2_6_2    
##  Min.   : 3.00   Min.   :1.000   Min.   : 1.00   Min.   : 2.0   
##  1st Qu.: 6.00   1st Qu.:2.000   1st Qu.: 4.00   1st Qu.: 6.0   
##  Median :10.00   Median :2.000   Median : 6.00   Median : 7.0   
##  Mean   : 8.56   Mean   :1.857   Mean   : 6.94   Mean   : 7.7   
##  3rd Qu.:10.00   3rd Qu.:2.000   3rd Qu.:10.00   3rd Qu.:10.0   
##  Max.   :10.00   Max.   :2.000   Max.   :99.00   Max.   :99.0   
##  NA's   :43289                   NA's   :37850   NA's   :42898  
##    P11_2_6_3         P11_3          P11_4_1         P11_4_2     
##  Min.   : 3.00   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.: 8.00   1st Qu.:1.000   1st Qu.:2.000   1st Qu.:2.000  
##  Median :10.00   Median :1.000   Median :2.000   Median :2.000  
##  Mean   : 9.13   Mean   :1.451   Mean   :1.947   Mean   :2.056  
##  3rd Qu.:10.00   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :99.00   Max.   :2.000   Max.   :3.000   Max.   :3.000  
##  NA's   :43839                   NA's   :19933   NA's   :19933  
##     P11_4_3         P11_4_4         P11_4_5         P11_5_1     
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000  
##  Median :2.000   Median :2.000   Median :2.000   Median :2.000  
##  Mean   :1.983   Mean   :2.027   Mean   :2.019   Mean   :1.985  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :3.000   Max.   :3.000   Max.   :3.000   Max.   :9.000  
##  NA's   :19933   NA's   :19933   NA's   :19933                  
##     P11_5_2         P11_5_3         P11_5_4         P11_5_5     
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000  
##  Median :2.000   Median :2.000   Median :2.000   Median :2.000  
##  Mean   :2.198   Mean   :2.029   Mean   :2.378   Mean   :2.064  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:3.000   3rd Qu.:2.000  
##  Max.   :9.000   Max.   :9.000   Max.   :9.000   Max.   :9.000  
##                                                                 
##     P11_5_6         P11_5_7         P11_5_8         P11_6_01        P11_6_02   
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.00  
##  1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.00  
##  Median :2.000   Median :2.000   Median :2.000   Median :2.000   Median :2.00  
##  Mean   :2.332   Mean   :2.128   Mean   :2.469   Mean   :1.983   Mean   :1.97  
##  3rd Qu.:3.000   3rd Qu.:2.000   3rd Qu.:3.000   3rd Qu.:2.000   3rd Qu.:2.00  
##  Max.   :9.000   Max.   :3.000   Max.   :9.000   Max.   :9.000   Max.   :9.00  
##  NA's   :26708   NA's   :10908   NA's   :10763                                 
##     P11_6_03        P11_6_04        P11_6_05        P11_6_06        P11_6_07   
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.00  
##  1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.00  
##  Median :2.000   Median :2.000   Median :2.000   Median :2.000   Median :2.00  
##  Mean   :1.951   Mean   :1.962   Mean   :1.978   Mean   :1.976   Mean   :1.96  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.00  
##  Max.   :9.000   Max.   :9.000   Max.   :9.000   Max.   :9.000   Max.   :9.00  
##                                                                                
##     P11_6_08        P11_6_09        P11_6_10        P11_6_11    
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000  
##  Median :2.000   Median :2.000   Median :2.000   Median :2.000  
##  Mean   :1.971   Mean   :1.966   Mean   :1.991   Mean   :1.999  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :9.000   Max.   :9.000   Max.   :9.000   Max.   :2.000  
##                                                  NA's   :1      
##      P11_7          P11_8_1         P11_8_2         P11_8_3     
##  Min.   :1.000   Min.   :1.00    Min.   :1.00    Min.   :1.00   
##  1st Qu.:1.000   1st Qu.:2.00    1st Qu.:2.00    1st Qu.:2.00   
##  Median :1.000   Median :2.00    Median :2.00    Median :2.00   
##  Mean   :1.669   Mean   :1.99    Mean   :1.97    Mean   :1.89   
##  3rd Qu.:3.000   3rd Qu.:2.00    3rd Qu.:2.00    3rd Qu.:2.00   
##  Max.   :3.000   Max.   :2.00    Max.   :2.00    Max.   :2.00   
##                  NA's   :37556   NA's   :37556   NA's   :37556  
##     P11_8_4         P11_8_5         P11_8_6         P12_1_1     
##  Min.   :1.00    Min.   :1.00    Min.   :1.00    Min.   :1.000  
##  1st Qu.:2.00    1st Qu.:1.00    1st Qu.:2.00    1st Qu.:1.000  
##  Median :2.00    Median :1.00    Median :2.00    Median :1.000  
##  Mean   :1.99    Mean   :1.15    Mean   :1.97    Mean   :1.736  
##  3rd Qu.:2.00    3rd Qu.:1.00    3rd Qu.:2.00    3rd Qu.:2.000  
##  Max.   :2.00    Max.   :2.00    Max.   :2.00    Max.   :9.000  
##  NA's   :37556   NA's   :37556   NA's   :37556                  
##     P12_1_2         P12_1_3          P12_2          P12_3_1        P12_3_2     
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.00   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:2.000   1st Qu.:3.00   1st Qu.:3.000  
##  Median :1.000   Median :2.000   Median :3.000   Median :3.00   Median :4.000  
##  Mean   :1.698   Mean   :1.861   Mean   :3.052   Mean   :3.13   Mean   :3.624  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:3.000   3rd Qu.:4.00   3rd Qu.:5.000  
##  Max.   :9.000   Max.   :9.000   Max.   :9.000   Max.   :9.00   Max.   :9.000  
##                                                                                
##     P12_3_3         P12_3_4         P12_3_5         P12_4_1     
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:2.000   1st Qu.:2.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :3.000   Median :3.000   Median :2.000   Median :2.000  
##  Mean   :3.305   Mean   :2.609   Mean   :2.693   Mean   :1.987  
##  3rd Qu.:5.000   3rd Qu.:3.000   3rd Qu.:4.000   3rd Qu.:3.000  
##  Max.   :9.000   Max.   :9.000   Max.   :9.000   Max.   :9.000  
##                                                                 
##     P12_4_2         P12_4_3         P12_4_4         P12_4_5        P12_4_6     
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.00   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.00   1st Qu.:1.000  
##  Median :2.000   Median :1.000   Median :1.000   Median :1.00   Median :1.000  
##  Mean   :2.783   Mean   :1.286   Mean   :1.384   Mean   :1.26   Mean   :1.276  
##  3rd Qu.:5.000   3rd Qu.:1.000   3rd Qu.:2.000   3rd Qu.:1.00   3rd Qu.:1.000  
##  Max.   :9.000   Max.   :9.000   Max.   :9.000   Max.   :9.00   Max.   :9.000  
##                                                                                
##     P12_5_1         P12_5_2        P12_5_3         P12_5_4         P12_5_5     
##  Min.   :1.000   Min.   :1.00   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.00   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :1.000   Median :1.00   Median :1.000   Median :1.000   Median :1.000  
##  Mean   :1.179   Mean   :1.26   Mean   :1.202   Mean   :1.184   Mean   :1.154  
##  3rd Qu.:1.000   3rd Qu.:1.00   3rd Qu.:1.000   3rd Qu.:1.000   3rd Qu.:1.000  
##  Max.   :9.000   Max.   :9.00   Max.   :9.000   Max.   :9.000   Max.   :9.000  
##                                                                                
##     P12_5_6       P12_5_7         P12_6_1         P12_6_2         P12_6_3     
##  Min.   :1.0   Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.0   1st Qu.:1.000   1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000  
##  Median :1.0   Median :1.000   Median :2.000   Median :2.000   Median :2.000  
##  Mean   :1.2   Mean   :1.361   Mean   :1.982   Mean   :1.884   Mean   :1.917  
##  3rd Qu.:1.0   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :9.0   Max.   :9.000   Max.   :9.000   Max.   :9.000   Max.   :9.000  
##                                                                               
##     P12_6_4         P12_6_5         P12_6_6           ENT       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   : 1.00  
##  1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000   1st Qu.: 9.00  
##  Median :2.000   Median :2.000   Median :2.000   Median :16.00  
##  Mean   :1.932   Mean   :2.001   Mean   :2.012   Mean   :16.51  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:24.00  
##  Max.   :9.000   Max.   :9.000   Max.   :9.000   Max.   :32.00  
##                                                                 
##     EST_DIS         UPM_DIS         FACTOR           les         
##  Min.   :  1.0   Min.   :   1   Min.   :   77   Min.   :0.00000  
##  1st Qu.:127.0   1st Qu.:1738   1st Qu.:  771   1st Qu.:0.00000  
##  Median :250.0   Median :3291   Median : 1453   Median :0.00000  
##  Mean   :249.6   Mean   :3314   Mean   : 2200   Mean   :0.03354  
##  3rd Qu.:369.0   3rd Qu.:4863   3rd Qu.: 2622   3rd Qu.:0.00000  
##  Max.   :513.0   Max.   :6374   Max.   :88053   Max.   :1.00000  
## 
library(dplyr)

# NA-Werte filtern und Dummy-Variable 'les' erstellen
disc_lab <- disc_lab %>%
  mutate(
    les = ifelse(P8_1 %in% c(1, 3, 6), 1, 0),
    P11_5_7 = ifelse(P11_5_7 == 9, NA, P11_5_7),
    P11_6_11 = ifelse(P11_6_11 == 9, NA, P11_6_11),
    P11_8_1 = ifelse(P11_8_1 == 9, NA, P11_8_1)
  )
table(disc_lab$les)
## 
##     0     1 
## 42707  1482
# Datensatz filtern, um nur 'les' == 1 zu behalten
quer_les <- disc_lab %>% filter(les == 1)

# Discriminierung laboral Codieren: 1 für "Sí", 0 für "Nein" und "No aplica"
quer_les <- quer_les %>%
  mutate(
    dicriminacion_lab1 = ifelse(P11_4_1 == 1, 1, 0),
    dicriminacion_lab2 = ifelse(P11_4_2 == 1, 1, 0),
    dicriminacion_lab3 = ifelse(P11_4_3 == 1, 1, 0),
    dicriminacion_lab4 = ifelse(P11_4_4 == 1, 1, 0),
    dicriminacion_lab5 = ifelse(P11_4_5 == 1, 1, 0),
    dicriminacion_lab6 = ifelse(P11_5_7 == 1, 1, 0)
  )

# Tabelle für 'dicriminacion_lab6' erstellen
table(quer_les$dicriminacion_lab6)
## 
##    0    1 
## 1050   82
# Discriminierung diario Codieren: 1 für "Sí", 0 für "Nein" und "No aplica"
quer_les <- quer_les %>%
  mutate(
    dicriminacion1 = ifelse(P11_6_11 == 1, 1, 0),
    dicriminacion2 = ifelse(P11_8_1 == 1, 1, 0),
    dicriminacion3 = ifelse(P11_8_2 == 1, 1, 0),
    dicriminacion4 = ifelse(P11_8_3 == 1, 1, 0),
    dicriminacion5 = ifelse(P11_8_4 == 1, 1, 0),
    dicriminacion6 = ifelse(P11_8_5 == 1, 1, 0)
  )

# Tabellen für die Diskriminierungsvariablen erstellen
table(quer_les$dicriminacion_lab1)
## 
##   0   1 
## 697 127
table(quer_les$dicriminacion_lab2)
## 
##   0   1 
## 765  59
table(quer_les$dicriminacion_lab3)
## 
##   0   1 
## 715 109
table(quer_les$dicriminacion_lab4)
## 
##   0   1 
## 721 103
table(quer_les$dicriminacion_lab5)
## 
##   0   1 
## 794  30
table(quer_les$dicriminacion_lab6)
## 
##    0    1 
## 1050   82
table(quer_les$dicriminacion1)
## 
##    0    1 
## 1458   24
table(quer_les$dicriminacion2)
## 
##   0   1 
## 232   9
table(quer_les$dicriminacion3)
## 
##   0   1 
## 209  32
table(quer_les$dicriminacion4)
## 
##   0   1 
## 208  33
table(quer_les$dicriminacion5)
## 
##   0   1 
## 220  21
table(quer_les$dicriminacion6)
## 
##   0   1 
##  85 156

4. Discriminierung laboral

variables <- c("dicriminacion_lab1", "dicriminacion_lab2", "dicriminacion_lab3", 
               "dicriminacion_lab4", "dicriminacion_lab5", "dicriminacion_lab6")

# Berechne die Häufigkeit der '1'-Werte (sí) für jede Variable
freq_si <- sapply(variables, function(var) sum(quer_les[[var]] == 1, na.rm = TRUE))

# Erstelle ein Balkendiagramm
barplot(freq_si, 
        names.arg = variables,  # Namen der Variablen auf der X-Achse
        col = "#FDFD96",      # Farbe für die Balken
        main = "Confirmación de la experiencia de discriminación laboral de lesbianas", 
        xlab = "Variable", 
        ylab = "Respuestas 'Sí' (1)", 
        ylim = c(0, max(freq_si) + 10))  # Y-Achse dynamisch basierend auf den Häufigkeiten

# Variablen definieren
variables <- c("dicriminacion_lab1", "dicriminacion_lab2", "dicriminacion_lab3", 
               "dicriminacion_lab4", "dicriminacion_lab5", "dicriminacion_lab6")

# Berechne die Häufigkeit der '1'-Werte (sí) für jede Variable
freq_si <- sapply(variables, function(var) sum(quer_les[[var]] == 1, na.rm = TRUE))

# Erstelle ein Balkendiagramm
barplot_heights <- barplot(freq_si, 
                           names.arg = variables,  # Namen der Variablen auf der X-Achse
                           col = "#FDFD96" ,      # Farbe für die Balken
                           main = "Confirmación de la experiencia de discriminación laboral de lesbianas", 
                           xlab = "Variable", 
                           ylab = "Respuestas 'Sí' (1)", 
                           ylim = c(0, max(freq_si) + 10))  # Y-Achse dynamisch basierend auf den Häufigkeiten

# Hinzufügen von genauen Werten auf den Balken
text(x = barplot_heights, y = freq_si, label = freq_si, pos = 3, cex = 0.8, col = "black")

# Variablen und die entsprechenden Fragen
variables <- c("dicriminacion_lab1", "dicriminacion_lab2", "dicriminacion_lab3", 
               "dicriminacion_lab4", "dicriminacion_lab5", "dicriminacion_lab6")

questions <- c(
  "¿en el trabajo recibió comentarios ofensivos o burlas?",
  "¿en el trabajo le excluyeron de eventos o actividades sociales?",
  "¿en el trabajo le molestaron o acosaron?",
  "¿en el trabajo recibió un trato desigual respecto a los beneficios, prestaciones laborales o ascensos?",
  "¿en el trabajo le pegaron, agredieron o amenazaron?",
  "¿le han negado injustificadamente el empleo o la oportunidad de trabajar?"
)

# Berechne die Häufigkeit der '1'-Werte (sí) und der '0'-Werte (no) für jede Variable
freq_si <- sapply(variables, function(var) sum(quer_les[[var]] == 1, na.rm = TRUE))
freq_no <- sapply(variables, function(var) sum(quer_les[[var]] == 0, na.rm = TRUE))

# Kombiniere die Häufigkeiten in einer Matrix
freq_matrix <- rbind(freq_si, freq_no)

# Erstelle Tortendiagramme für jede Variable
par(mfrow = c(2, 3), mar = c(5, 5, 2, 2))  # Setze Ränder für bessere Sichtbarkeit
for (i in 1:length(variables)) {
  # Erstelle das Tortendiagramm
  pie(freq_matrix[, i], 
      labels = paste(c("Sí", "No"), ": ", freq_matrix[, i]), 
      col = c("#FFFACD","#CBAACB" ), 
      main = strwrap(questions[i], width = 40),  # Umbrüche einfügen
      cex.main = 0.8)  # Verkleinerung der Schriftgröße des Titels
}

# Variable und entsprechende Fragen
variables <- c("dicriminacion_lab1", "dicriminacion_lab2", "dicriminacion_lab3", 
               "dicriminacion_lab4", "dicriminacion_lab5", "dicriminacion_lab6")

questions <- c(
  "¿en el trabajo recibió comentarios ofensivos o burlas?",
  "¿en el trabajo le excluyeron de eventos o actividades sociales?",
  "¿en el trabajo le molestaron o acosaron?",
  "¿en el trabajo recibió un trato desigual respecto a los beneficios, prestaciones laborales o ascensos?",
  "¿en el trabajo le pegaron, agredieron o amenazaron?",
  "¿le han negado injustificadamente el empleo o la oportunidad de trabajar?"
)

# Berechne die Häufigkeit der '1'-Werte (sí) und der '0'-Werte (no) für jede Variable
freq_si <- sapply(variables, function(var) sum(quer_les[[var]] == 1, na.rm = TRUE))
freq_no <- sapply(variables, function(var) sum(quer_les[[var]] == 0, na.rm = TRUE))

# Berechne die Gesamtanzahl der Beobachtungen für jede Variable
total <- freq_si + freq_no

# Berechne die prozentuale Häufigkeit
percent_si <- (freq_si / total) * 100
percent_no <- (freq_no / total) * 100

# Kombiniere die Prozentangaben in einer Matrix
percent_matrix <- rbind(percent_si, percent_no)

# Erstelle Tortendiagramme für jede Variable
par(mfrow = c(2, 3), mar = c(5, 5, 2, 2))  # Setze Ränder für bessere Sichtbarkeit
for (i in 1:length(variables)) {
  # Erstelle das Tortendiagramm
  pie(percent_matrix[, i], 
      labels = paste(c("Sí", "No"), ": ", round(percent_matrix[, i], 1), "%"), 
      col = c("#FFFACD","#CBAACB" ), 
      main = strwrap(questions[i], width = 40),  # Umbrüche aAdding interpretable line breaks Haupttitel
      cex.main = 0.8)  # Verkleinerung der Schriftgröße des Titels
}

# Variablen, die du vergleichen möchtest
variables <- c("dicriminacion_lab1", "dicriminacion_lab2", "dicriminacion_lab3", 
               "dicriminacion_lab4", "dicriminacion_lab5", "dicriminacion_lab6")

# Berechne die Häufigkeit der '1'-Werte (Sí) und '0'-Werte (No) für jede Variable
freq_si <- sapply(variables, function(var) sum(quer_les[[var]] == 1, na.rm = TRUE))
freq_no <- sapply(variables, function(var) sum(quer_les[[var]] == 0, na.rm = TRUE))

# Berechne die Verhältnisse (prozentuale Anteile) für Sí und No
total_responses <- freq_si + freq_no
percent_si <- (freq_si / total_responses) * 100
percent_no <- (freq_no / total_responses) * 100

# Erstelle eine Matrix mit den Häufigkeiten
freq_matrix <- rbind(freq_no, freq_si)

# Farben definieren
farben <- c("#CBAACB", "#FFFACD")  # Farben für No und Sí

# Erstelle das Balkendiagramm der Häufigkeiten
barplot_heights <- barplot(freq_matrix, 
                           beside = TRUE,  # Nebeneinander darstellen
                           col = farben,  # Farben für No und Sí
                           names.arg = variables,  # Variablennamen auf der x-Achse
                           main = "Comparación de los porcentajes de 'Sí' (1) y 'No' (0)",  # Titel
                           xlab = "Variable", 
                           ylab = "Frecuencia", 
                           legend.text = c("No", "Sí"),  # Legende
                           args.legend = list(x = "topright", bty = "n"),  # Legendenposition
                           ylim = c(0, max(freq_matrix) + 50))  # Y-Achse dynamisch basierend auf den Häufigkeiten

# Hinzufügen von genauen Werten und Prozenten direkt an den Balken
text(x = barplot_heights[1,], y = freq_matrix[1,] + 5, labels = paste0(freq_matrix[1,], " (", round(percent_no, 1), "%)"), pos = 3, cex = 0.8, col = "black")
text(x = barplot_heights[2,], y = freq_matrix[2,] + 5, labels = paste0(freq_matrix[2,], " (", round(percent_si, 1), "%)"), pos = 3, cex = 0.8, col = "black")

table(quer_les$dicriminacion_lab1)
## 
##   0   1 
## 697 127
variables <- c("dicriminacion_lab1", "dicriminacion_lab2", "dicriminacion_lab3", 
               "dicriminacion_lab4", "dicriminacion_lab5", "dicriminacion_lab6")


freq_si <- sapply(variables, function(var) sum(quer_les[[var]] == 1, na.rm = TRUE))
freq_no <- sapply(variables, function(var) sum(quer_les[[var]] == 0, na.rm = TRUE))


freq_matrix <- rbind(freq_no, freq_si)  


barplot(freq_matrix, 
        beside = TRUE,  
        col = c("#CBAACB", "#FFFACD"),  
        names.arg = variables,  
        main = "Comparación de los porcentajes de 'Sí' (1) y 'No' (0)",  
        xlab = "Variable", 
        ylab = "Frecuencia", 
        legend.text = c("No", "Sí"),  
        ylim = c(0, max(freq_matrix) + 50))  

5. Discriminación general

Aunque la investigación se centra en la discriminación hacia las mujeres lesbianas, también se considera importante mostrar cómo es el mundo, donde existe discriminación contra las mujeres no heterosexuales en general.

# Variablen, die du vergleichen möchtest
variables <- c("dicriminacion1", "dicriminacion2", "dicriminacion3", 
               "dicriminacion4", "dicriminacion5", "dicriminacion6")

# Berechne die Häufigkeit der '1'-Werte (Sí) und '0'-Werte (No) für jede Variable
freq_si <- sapply(variables, function(var) sum(quer_les[[var]] == 1, na.rm = TRUE))
freq_no <- sapply(variables, function(var) sum(quer_les[[var]] == 0, na.rm = TRUE))

# Berechne die Verhältnisse (prozentuale Anteile) für Sí und No
total_responses <- freq_si + freq_no
ratio_si <- freq_si / total_responses
ratio_no <- freq_no / total_responses

# Erstelle eine Matrix mit den Verhältnissen
ratio_matrix <- rbind(ratio_no, ratio_si)

# Definiere Farben
farben <- c("Sí" = "#FFC0CB", "No" = "#AEC6CF")

# Erstelle das Balkendiagramm der Verhältnisse
barplot_heights <- barplot(ratio_matrix, 
                           beside = TRUE,  # Nebeneinander darstellen
                           col = farben,  # Farben für No und Sí
                           names.arg = variables,  # Variablennamen auf der x-Achse
                           main = "Comparación de los porcentajes de 'Sí' (1) y 'No' (0)",  # Titel
                           xlab = "Variable", 
                           ylab = "Relación", 
                           legend.text = c("No", "Sí"),  # Legende
                           args.legend = list(x = "topright", bty = "n"),  # Legendenposition
                           ylim = c(0, 1))  # Y-Achse für Verhältnisse zwischen 0 und 1

# Hinzufügen von genauen Werten auf den Balken
text(x = barplot_heights[1,], y = ratio_matrix[1,] - 0.05, labels = round(ratio_matrix[1,], 2), pos = 1, cex = 0.8, col = "black")
text(x = barplot_heights[2,], y = ratio_matrix[2,] - 0.05, labels = round(ratio_matrix[2,], 2), pos = 1, cex = 0.8, col = "black")

# Variablen, die du vergleichen möchtest
variables <- c("dicriminacion1", "dicriminacion2", "dicriminacion3", 
               "dicriminacion4", "dicriminacion5", "dicriminacion6")

# Berechne die Häufigkeit der '1'-Werte (Sí) für jede Variable
freq_si <- sapply(variables, function(var) sum(quer_les[[var]] == 1, na.rm = TRUE))

# Erstelle das Balkendiagramm nur für die Sí-Antworten
barplot_heights <- barplot(freq_si, 
                           col = "#AEC6CF",  # Farbe für Sí-Antworten
                           names.arg = variables,  # Variablennamen auf der x-Achse
                           main = "Confirmación de la experiencia de discriminación laboral de lesbianas",  # Titel
                           xlab = "Variable", 
                           ylab = "Respuestas Sí (1)", 
                           ylim = c(0, max(freq_si) + 50))  # Y-Achse dynamisch basierend auf den Häufigkeiten

# Hinzufügen von genauen Werten auf den Balken
text(x = barplot_heights, y = freq_si, label = freq_si, pos = 3, cex = 0.8, col = "black")

# Variablen und die zugehörigen Fragen
questions <- c(
  "¿ha sido discriminada(o), o menospreciada(o), por su preferencia sexual?", 
  "¿Usted no toma de la mano a su pareja o le muestra su afecto en público por miedo a sufrir agresión o violencia?", 
  "¿Usted no toma de la mano a su pareja o le muestra su afecto en público por ser mal visto socialmente?", 
  "¿Usted no toma de la mano a su pareja o le muestra su afecto en público por pena o vergüenza?", 
  "¿Usted no toma de la mano a su pareja o le muestra su afecto en público por temor a ser discriminada(o)?", 
  "¿Usted no toma de la mano a su pareja o le muestra su afecto en público por falta de costumbre?"
)

# Variablen, die du vergleichen möchtest
variables <- c("dicriminacion1", "dicriminacion2", "dicriminacion3", 
               "dicriminacion4", "dicriminacion5", "dicriminacion6")

# Erstelle eine Funktion, um für jede Variable ein Tortendiagramm zu erstellen
par(mfrow = c(2, 3))  # Zwei Reihen und drei Spalten für die Diagramme

for (i in 1:length(variables)) {
  var <- variables[i]
  question <- questions[i]
  
  # Breche die Frage in mehrere Zeilen
  wrapped_question <- strwrap(question, width = 40)  # 40 Zeichen pro Zeile
  
  # Berechne die Häufigkeit der '1' (Sí) und '0' (No) für jede Variable
  freq <- table(quer_les[[var]])
  
  # Erstelle das Tortendiagramm für jede Variable
  pie(freq, 
      main = paste(wrapped_question, collapse = "\n"),  # Frage in mehreren Zeilen als Titel
      col = c("#FFC0CB", "#AEC6CF"),  # Farben für No (0) und Sí (1)
      labels = paste(c("No", "Sí"), "\n", round(100 * freq / sum(freq), 1), "%"),  # Prozentsätze anzeigen
      cex.main = 0.8)  # Verkleinere die Schriftgröße des Titels (Fragen)
}

Matrimonio igualitario

# Benötigte Bibliotheken laden
library(sf)
## Warning: Paket 'sf' wurde unter R Version 4.4.2 erstellt
## Linking to GEOS 3.12.2, GDAL 3.9.3, PROJ 9.4.1; sf_use_s2() is TRUE
library(ggplot2)
library(dplyr)

# Shapefile einlesen
mexmex <- st_read("C:/Master/3. Semester/R/Dataset/gadm41_MEX.gpkg", layer = "ADM_ADM_1")
## Reading layer `ADM_ADM_1' from data source 
##   `C:\Master\3. Semester\R\Dataset\gadm41_MEX.gpkg' using driver `GPKG'
## Simple feature collection with 32 features and 11 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -118.3665 ymin: 14.53507 xmax: -86.71074 ymax: 32.71863
## Geodetic CRS:  WGS 84
# Daten zu den Jahren der Einführung der Ehe für alle in den Bundesstaaten
matrimonio_data <- data.frame(
  estado = c( "Quintana Roo", "Coahuila", "Chihuahua", "Nayarit", 
             "Campeche", "Michoacán", "Morelos", "Colima", "Chiapas", 
             "Nuevo León", "San Luis Potosí", "Hidalgo", "Baja California Sur", 
             "Aguascalientes", "Oaxaca", "Puebla", "Tlaxcala", "Sinaloa", 
             "Baja California", "Yucatán", "Querétaro", "Sonora", "Zacatecas", 
             "Guanajuato", "Jalisco", "Veracruz", "Durango", "México", 
             "Tabasco", "Guerrero", "Tamaulipas", "Distrito Federal"),
  jahr = c(2012, 2014, 2015, 2015, 2016, 2016, 2016, 2016, 2017, 
           2019, 2019, 2019, 2019, 2019, 2019, 2020, 2020, 2021, 
           2021, 2021, 2021, 2021, 2021, 2021, 2022, 2022, 2022, 
           2022, 2022, 2022, 2022, 2010)
)

# Daten mit Shapefile verbinden
mexmex <- mexmex %>%
  left_join(matrimonio_data, by = c("NAME_1" = "estado"))

# Karte erstellen
ggplot(data = mexmex) +
  geom_sf(aes(fill = jahr)) +
  scale_fill_continuous(name = "Jahr der Einführung", low = "lightblue", high = "darkblue") +
  labs(title = "Einführung der Ehe für alle in Mexiko",
       caption = "Quelle: Maguey 2022") +
  theme_minimal()

# Anzeigen der Namen der Bundesstaaten im Shapefile
unique(mexmex$NAME_1)
##  [1] "Aguascalientes"      "Baja California"     "Baja California Sur"
##  [4] "Campeche"            "Chiapas"             "Chihuahua"          
##  [7] "Coahuila"            "Colima"              "Distrito Federal"   
## [10] "Durango"             "Guanajuato"          "Guerrero"           
## [13] "Hidalgo"             "Jalisco"             "México"             
## [16] "Michoacán"           "Morelos"             "Nayarit"            
## [19] "Nuevo León"          "Oaxaca"              "Puebla"             
## [22] "Querétaro"           "Quintana Roo"        "San Luis Potosí"    
## [25] "Sinaloa"             "Sonora"              "Tabasco"            
## [28] "Tamaulipas"          "Tlaxcala"            "Veracruz"           
## [31] "Yucatán"             "Zacatecas"
# Benötigte Bibliotheken laden
library(sf)
library(ggplot2)
library(dplyr)

# Shapefile einlesen
mexmex <- st_read("C:/Master/3. Semester/R/Dataset/gadm41_MEX.gpkg", layer = "ADM_ADM_1")
## Reading layer `ADM_ADM_1' from data source 
##   `C:\Master\3. Semester\R\Dataset\gadm41_MEX.gpkg' using driver `GPKG'
## Simple feature collection with 32 features and 11 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -118.3665 ymin: 14.53507 xmax: -86.71074 ymax: 32.71863
## Geodetic CRS:  WGS 84
# Daten zu den Jahren der Einführung der Ehe für alle in den Bundesstaaten
matrimonio_data <- data.frame(
  estado = c("Distrito Federal", "Quintana Roo", "Coahuila", "Chihuahua", "Nayarit", 
             "Campeche", "Michoacán", "Morelos", "Colima", "Chiapas", 
             "Nuevo León", "San Luis Potosí", "Hidalgo", "Baja California Sur", 
             "Aguascalientes", "Oaxaca", "Puebla", "Tlaxcala", "Sinaloa", 
             "Baja California", "Yucatán", "Querétaro", "Sonora", "Zacatecas", 
             "Guanajuato", "Jalisco", "Veracruz", "Durango", "México", 
             "Tabasco", "Guerrero", "Tamaulipas"),
  jahr = c(2010, 2012, 2014, 2015, 2015, 2016, 2016, 2016, 2016, 2017, 
           2019, 2019, 2019, 2019, 2019, 2019, 2020, 2020, 2021, 
           2021, 2021, 2021, 2021, 2021, 2021, 2022, 2022, 2022, 
           2022, 2022, 2022, 2022)
)

# Anpassung der Namen in den Daten, um sie den Namen im Shapefile anzupassen
matrimonio_data$estado <- gsub("Ciudad de México", "Mexico City", matrimonio_data$estado)
matrimonio_data$estado <- gsub("Estado de México", "Mexico State", matrimonio_data$estado)

# Daten mit Shapefile verbinden
mexmex <- mexmex %>%
  left_join(matrimonio_data, by = c("NAME_1" = "estado"))

# Farben definieren
farben <- c("2010" = "#FFD700", "2012" = "#FFA500", "2014" = "#800080", "2015" = "#FF0000",
            "2016" = "#FF69B4", "2017" = "#0000FF", "2019" = "#008000", "2020" = "#2171b5",
            "2021" = "#FF6347", "2022" = "#6A5ACD")

# Karte erstellen
ggplot(data = mexmex) +
  geom_sf(aes(fill = as.factor(jahr))) +
  scale_fill_manual(values = farben, name = "Jahr der Einführung") +
  labs(title = "Einführung der Ehe für alle in Mexiko",
       caption = "Quelle: Maguey 2022") +
  theme_minimal()

# Benötigte Bibliotheken laden
library(sf)
library(ggplot2)
library(dplyr)

# Shapefile einlesen
mexmex <- st_read("C:/Master/3. Semester/R/Dataset/gadm41_MEX.gpkg", layer = "ADM_ADM_1")
## Reading layer `ADM_ADM_1' from data source 
##   `C:\Master\3. Semester\R\Dataset\gadm41_MEX.gpkg' using driver `GPKG'
## Simple feature collection with 32 features and 11 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -118.3665 ymin: 14.53507 xmax: -86.71074 ymax: 32.71863
## Geodetic CRS:  WGS 84
# Daten zu den Jahren der Einführung der Ehe für alle in den Bundesstaaten
matrimonio_data <- data.frame(
  estado = c("Distrito Federal", "Quintana Roo", "Coahuila", "Chihuahua", "Nayarit", 
             "Campeche", "Michoacán", "Morelos", "Colima", "Chiapas", 
             "Nuevo León", "San Luis Potosí", "Hidalgo", "Baja California Sur", 
             "Aguascalientes", "Oaxaca", "Puebla", "Tlaxcala", "Sinaloa", 
             "Baja California", "Yucatán", "Querétaro", "Sonora", "Zacatecas", 
             "Guanajuato", "Jalisco", "Veracruz", "Durango", "México", 
             "Tabasco", "Guerrero", "Tamaulipas"),
  jahr = c(2010, 2012, 2014, 2015, 2015, 2016, 2016, 2016, 2016, 2017, 
           2019, 2019, 2019, 2019, 2019, 2019, 2020, 2020, 2021, 
           2021, 2021, 2021, 2021, 2021, 2021, 2022, 2022, 2022, 
           2022, 2022, 2022, 2022)
)

# Anpassung der Namen in den Daten, um sie den Namen im Shapefile anzupassen
matrimonio_data$estado <- gsub("Ciudad de México", "Mexico City", matrimonio_data$estado)
matrimonio_data$estado <- gsub("Estado de México", "Mexico State", matrimonio_data$estado)

# Daten mit Shapefile verbinden
mexmex <- mexmex %>%
  left_join(matrimonio_data, by = c("NAME_1" = "estado"))

# Farben definieren
farben <- c("2010" = "#1f78b4", "2012" = "#33a02c", "2014" = "#e31a1c", "2015" = "#ff7f00",
            "2016" = "#6a3d9a", "2017" = "#b15928", "2019" = "#a6cee3", "2020" = "#b2df8a",
            "2021" = "#fb9a99", "2022" = "#fdbf6f")

# Karte erstellen
ggplot(data = mexmex) +
  geom_sf(aes(fill = as.factor(jahr))) +
  scale_fill_manual(values = farben, name = "Jahr der Einführung") +
  labs(title = "Einführung der Ehe für alle in Mexiko",
       caption = "Quelle: Maguey 2022") +
  theme_minimal()

# Bibliotecas necesarias
library(sf)
library(ggplot2)
library(dplyr)

# Leer el archivo Shapefile
mexmex <- st_read("C:/Master/3. Semester/R/Dataset/gadm41_MEX.gpkg", layer = "ADM_ADM_1")
## Reading layer `ADM_ADM_1' from data source 
##   `C:\Master\3. Semester\R\Dataset\gadm41_MEX.gpkg' using driver `GPKG'
## Simple feature collection with 32 features and 11 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -118.3665 ymin: 14.53507 xmax: -86.71074 ymax: 32.71863
## Geodetic CRS:  WGS 84
# Datos sobre los años de introducción del matrimonio igualitario en los estados
datos_matrimonio <- data.frame(
  estado = c("Distrito Federal", "Quintana Roo", "Coahuila", "Chihuahua", "Nayarit", 
             "Campeche", "Michoacán", "Morelos", "Colima", "Chiapas", 
             "Nuevo León", "San Luis Potosí", "Hidalgo", "Baja California Sur", 
             "Aguascalientes", "Oaxaca", "Puebla", "Tlaxcala", "Sinaloa", 
             "Baja California", "Yucatán", "Querétaro", "Sonora", "Zacatecas", 
             "Guanajuato", "Jalisco", "Veracruz", "Durango", "México", 
             "Tabasco", "Guerrero", "Tamaulipas"),
  año = c(2010, 2012, 2014, 2015, 2015, 2016, 2016, 2016, 2016, 2017, 
          2019, 2019, 2019, 2019, 2019, 2019, 2020, 2020, 2021, 
          2021, 2021, 2021, 2021, 2021, 2021, 2022, 2022, 2022, 
          2022, 2022, 2022, 2022)
)

# Ajustar los nombres en los datos para que coincidan con los nombres en el Shapefile
datos_matrimonio$estado <- gsub("Ciudad de México", "Mexico City", datos_matrimonio$estado)
datos_matrimonio$estado <- gsub("Estado de México", "Mexico State", datos_matrimonio$estado)

# Unir los datos con el Shapefile
mexmex <- mexmex %>%
  left_join(datos_matrimonio, by = c("NAME_1" = "estado"))

# Definir colores
colores <- c("2010" = "#1f78b4", "2012" = "#33a02c", "2014" = "#e31a1c", "2015" = "#ff7f00",
             "2016" = "#6a3d9a", "2017" = "#FFD700", "2019" = "#a6cee3", "2020" = "#b2df8a",
             "2021" = "#fb9a99", "2022" = "#fdbf6f")

# Crear el mapa
ggplot(data = mexmex) +
  geom_sf(aes(fill = as.factor(año))) +
  scale_fill_manual(values = colores, name = "Año de Introducción") +
  labs(title = "Introducción del Matrimonio Igualitario en México",
       caption = "Fuente: Maguey 2022") +
  theme_minimal()

Matrimonio igualitario