library(readxl)
## Warning: package 'readxl' was built under R version 4.2.3
library(readxl)
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.2.2
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyr)
## Warning: package 'tidyr' was built under R version 4.2.3
library(ggplot2)
library(wordcloud)
## Warning: package 'wordcloud' was built under R version 4.2.3
## Carregando pacotes exigidos: RColorBrewer
library(RColorBrewer)
library(tm)
## Warning: package 'tm' was built under R version 4.2.3
## Carregando pacotes exigidos: NLP
##
## Attaching package: 'NLP'
## The following object is masked from 'package:ggplot2':
##
## annotate
# Leer datos (ajusta el nombre si tu archivo o sheet es diferente)
df <- read_excel("C:/Users/PC/Desktop/sinai/Formulario sin título (Respuestas).xlsx", sheet = 1)
df <- df %>% rename(
Edad = `1.1. Edad`,
Genero = `1.2. Género`,
Residencia = `1.3. Tiempo de residencia en el barrio.`,
Escolaridad = `1.4. Último nivel de escolaridad`,
Num_personas = `1.5. ¿Cantidad de personas que viven en su unidad habitacional o casa?`,
Condiciones = `1.6. ¿En su casa vive alguien con alguna de estas condiciones?`,
Exposicion = `2.1. ¿Considera que su comunidad está expuesta al riesgo de deslizamiento?`,
Preocupacion = `2.2. ¿Qué tan preocupado se siente usted de que pueda haber un riesgo de deslizamiento?`,
Evento_conocido = `2.3. ¿Ha presenciado o conocido algún evento de deslizamiento en su comunidad?`,
Descripcion_evento= `2.3.1 En caso de que la pregunta anterior sea afirmativa, por favor, describa el evento (¿Hace cuánto tiempo sucedió y cómo le afectó a usted este evento?)`,
Afectacion = `2.4. ¿Ha tenido alguna afectación en su casa a causa de un deslizamiento?`,
Conoce_medidas = `2.5. ¿Conoce usted alguna medida preventiva para evitar los deslizamientos?`,
Medidas_conocidas = `2.5.1 En caso de que la pregunta anterior sea afirmativo, por favor, seleccione cuáles conoce:`,
Preparado = `2.6. ¿Considera que se encuentra preparad@ ante el riesgo del deslizamiento?`,
Opciones_preparac = `2.6.1. En caso de que la pregunta anterior sea afirmativo, por favor, seleccione todas las opciones que considera que apliquen:`,
Ha_tomado_medida = `2. 7. ¿Ha tomado alguna medida para prepararse ante el riesgo de deslizamiento?`,
Medidas_tomadas = `2.7.1 En caso de que la pregunta anterior sea afirmativo, ¿Qué medida(s) ha tomado?`,
Capacita = `2.8. ¿Ha recibido capacitación o apoyo de alguna institución o persona(s) relacionado con el riesgo de deslizamiento?`,
Fuente_cap = `2.8.1 En caso de que la pregunta anterior (2.8) sea afirmativo ¿De parte de qué institución o persona(s) ha recibido esta capacitación o apoyo?`,
Familia_cap = `2.8.2 En caso de que la pregunta anterior sea afirmativo ¿Quién o quiénes de su familia lo han recibido?`,
Necesita_cap = `2.8.3 En caso de que la respuesta a la pregunta 2.8 sea negativo, ¿considera necesario recibir una capacitación relacionada con la preparación ante el riesgo de deslizamiento?`,
Conoce_grupo = `2.9. ¿Conoce si existe algún grupo comunitario organizado en Sinaí en caso de emergencia?`,
Participa_grupo = `2.9.1 En caso de que la pregunta anterior sea afirmativo, ¿participa usted en esta organización comunitaria?`
)
# VISTA RÁPIDA DE NOMBRES DE COLUMNAS
names(df)
## [1] "Numero encuesta" "Marca temporal (Fecha)" "Edad"
## [4] "Genero" "Residencia" "Escolaridad"
## [7] "Num_personas" "Condiciones" "Exposicion"
## [10] "Preocupacion" "Evento_conocido" "Descripcion_evento"
## [13] "Afectacion" "Conoce_medidas" "Medidas_conocidas"
## [16] "Preparado" "Opciones_preparac" "Ha_tomado_medida"
## [19] "Medidas_tomadas" "Capacita" "Fuente_cap"
## [22] "Familia_cap" "Necesita_cap" "Conoce_grupo"
## [25] "Participa_grupo"
### 1.1. Edad. VS 2.2. Preocupación ante el riesgo de deslizamiento.
ggplot(df, aes(x=Edad, fill=Preocupacion)) +
geom_bar(position="dodge") +
labs(
x="Edad",
y="Frecuencia",
fill="¿Considera comunidad expuesta al riesgo de deslizamiento?",
title="Edad vs. Preocupacion riesgo de deslizamiento"
) +
theme_minimal(base_family = "Times", base_size = 14)
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

### 1.4. Último nivel de escolaridad. VS 2.2. Preocupación ante el riesgo de deslizamiento.
library(ggmosaic)
## Warning: package 'ggmosaic' was built under R version 4.2.3
ggplot(data = df) +
geom_mosaic(aes(weight = 1, x = product(Escolaridad), fill=Preocupacion)) +
labs(
x="Escolaridad",
y="Proporción",
fill="¿Considera comunidad expuesta al riesgo de deslizamiento?",
title="Mosaico: Escolaridad vs. Preocupacion riesgo de deslizamiento"
) +
theme_minimal(base_family = "Times", base_size = 14)
## Warning: The `scale_name` argument of `continuous_scale()` is deprecated as of ggplot2
## 3.5.0.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: The `trans` argument of `continuous_scale()` is deprecated as of ggplot2 3.5.0.
## ℹ Please use the `transform` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: `unite_()` was deprecated in tidyr 1.2.0.
## ℹ Please use `unite()` instead.
## ℹ The deprecated feature was likely used in the ggmosaic package.
## Please report the issue at <]8;;https://github.com/haleyjeppson/ggmosaichttps://github.com/haleyjeppson/ggmosaic]8;;>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

### 1.2. Género. VS2.2. Preocupación ante el riesgo de deslizamiento.
ggplot(df, aes(x=Genero, fill=Preocupacion)) +
geom_bar() +
labs(
x="Género.",
y="Frecuencia",
fill="¿Considera comunidad expuesta al riesgo de deslizamiento?",
title="Género. vs. Preocupación ante el riesgo de deslizamiento."
) +
theme_minimal(base_family = "Times", base_size = 14)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

### 1.4. Último nivel de escolaridad. VS 2.5. Si conoce o no alguna medida preventiva para evitar los deslizamientos.
####### (Ya se hizo)
### 1.1. Edad. VS 2.6. Percepción personal sobre si se encuentra preparad@ o no ante el riesgo del deslizamiento.
ggplot(df, aes(x=Edad, fill=Preparado)) +
geom_bar(position="fill") +
labs(
x="Edad",
y="Proporción",
fill="¿Preparado ante el riesgo del deslizamiento?",
title="Edad vs. Preparado ante el riesgo del deslizamiento"
) +
scale_y_continuous(labels = scales::percent_format()) +
theme_minimal(base_family = "Times", base_size = 14)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

### 1.2. Género. VS 2.7. Si ha tomado alguna medida o no para prepararse ante el riesgo de deslizamiento.
ggplot(df, aes(x=Genero, fill=Ha_tomado_medida)) +
geom_bar(position="dodge") +
labs(
x="Género",
y="Frecuencia",
fill="¿Ha tomado medidas prepararse ante riesgo deslizamiento?",
title="Género vs. Medida para prepararse ante el riesgo de deslizamiento"
) +
theme_minimal(base_family = "Times", base_size = 14)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

### 1.4. Último nivel de escolaridad. VS 2.8.3. Si se considera necesario o no recibir una capacitación relacionada con la preparación ante el riesgo de deslizamiento.
ggplot(df, aes(x=Escolaridad, fill=Necesita_cap)) +
geom_bar(position="dodge") +
labs(
x="Escolaridad",
y="Frecuencia",
fill="¿considera necesario o no recibir una capacitación?",
title="Género vs. considera necesario o no recibir una capacitación"
) +
theme_minimal(base_family = "Times", base_size = 14)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

### 1.2. Género.VS 2.8.3. Si se considera necesario o no recibir una capacitación relacionada con la preparación ante el riesgo de deslizamiento.
library(ggplot2)
# Cambia los nombres de columna según tu base
ggplot(df, aes(x=Genero, fill=Necesita_cap)) +
geom_bar(position="dodge") +
labs(
x="Género",
y="Frecuencia",
fill="¿Necesita capacitación?",
title="Género vs. Necesidad de capacitación"
) +
theme_minimal(base_family = "Times", base_size = 14)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

############### otross
############ Asociación entre Escolaridad, y Conoce_medidas
ggplot(df, aes(x=Escolaridad, fill=Conoce_medidas)) +
geom_bar() +
labs(
x="Nivel de escolaridad",
y="Frecuencia",
fill="¿Conoce medidas preventivas?",
title="Escolaridad vs. Conocimiento de medidas"
) +
theme_minimal(base_family = "Times", base_size = 14)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

############ Asociación entre Genero - Ha_Tomado_Medidas
ggplot(df, aes(x=Genero, fill=Ha_tomado_medida)) +
geom_bar(position="fill") +
labs(
x="Género",
y="Proporción",
fill="¿Ha tomado medidas?",
title="Género vs. Toma de medidas preventivas"
) +
scale_y_continuous(labels = scales::percent_format()) +
theme_minimal(base_family = "Times", base_size = 14)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

############ Asociación entre Género vs. Necesidad de capacitación
library(ggmosaic)
ggplot(data = df) +
geom_mosaic(aes(weight = 1, x = product(Genero), fill=Necesita_cap)) +
labs(
x="Género",
y="Proporción",
fill="¿Necesita capacitación?",
title="Mosaico: Género vs. Necesidad de capacitación"
) +
theme_minimal(base_family = "Times", base_size = 14)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

table_prop <- prop.table(table(df$Genero, df$Necesita_cap), 1)
round(100 * table_prop, 1) # Porcentajes por fila
##
## No Sí
## Femenino 4.3 95.7
## Masculino 0.0 100.0
# ggsave("grafico.png", width=6, height=4, dpi=600)