Lectura de datos

load("Icfes162.RData")

Bibliotecas

library(tidyr)
library(dplyr)
library(ggplot2)
library(ggthemes)
library(DT)
library(pander)
library(plotly)

1. ¿Cuántos registros tiene la base de datos correspondientes a prueba en calidad de estudiante e individual?

rta_1 <- icfes %>%
  group_by(ESTU_ESTUDIANTE) %>%
  count()

pander(rta_1)
ESTU_ESTUDIANTE n
ESTUDIANTE 567777
INDIVIDUAL 38205
r1 <- ggplot(data = rta_1, aes(x = ESTU_ESTUDIANTE, y = n)) +
        geom_bar(stat = "identity",
                 fill = c("gray15", "gray50"),
                 color = "red") + 
        geom_text(aes(label = n),
                  size = 8,
                  color = c("white", "black"), 
                  position = position_stack(vjust = 0.5)) +
        labs(x = "",
             y = "Número de registros",
             main = "") + 
        theme_classic()

r1

2. ¿Qué porcentaje de registros correspondientes a calidad de estudiante e individual tiene la base de datos?

rta_2 <- rta_1 %>%
  ungroup() %>%
  mutate(Total = sum(n),
         porcentaje = n/Total * 100,
         n_miles = n/1000)

pander(rta_2)
ESTU_ESTUDIANTE n Total porcentaje n_miles
ESTUDIANTE 567777 605982 93.7 567.8
INDIVIDUAL 38205 605982 6.305 38.2
r2 <- ggplot(data = rta_2, aes(x = ESTU_ESTUDIANTE, y = porcentaje)) +
        geom_bar(stat = "identity", 
                 fill = c("gray15", "gray50"),
                 color = "red") + 
        geom_text(aes(label = round(porcentaje, digits = 1)),
                  size = 8,
                  color = c("white", "black"), 
                  position = position_stack(vjust = 0.5)) +
        labs(x = "",
             y = "Porcentaje de registros",
             main = "") + 
        theme_classic()

r2

3. ¿Cómo se distribuye la edad de las personas que presentaron la prueba?

r3 <- ggplot(data = icfes, aes(x = ESTU_EDAD)) + 
        geom_histogram(bins = 100,
                       fill = "gray15",
                       color = "red") +
        labs(x = "Edad",
             y = "Frecuencia") + 
        theme_classic()

r3

4. ¿Qué porcentaje de personas que presentaron la prueba son mayores de edad?

rta_4 <- icfes %>%
  filter(ESTU_EDAD >= 18) %>%
  count() %>%
  mutate(Total = 605982,
         porcentaje = n/Total * 100)

pander(rta_4)
n Total porcentaje
241936 605982 39.92

5. ¿Cuántas mujeres (como frecuencia absoluta y relativa) mayores de edad y con calidad de estudiante presentaron la prueba?

rta_5 <- icfes %>%
  filter(ESTU_GENERO == "F" & ESTU_EDAD >= 18) %>%
  group_by(ESTU_ESTUDIANTE) %>%
  count() %>%
  ungroup() %>%
  mutate(Total_Mujeres = sum(n),
         Gran_Total = 605982,
         Porcentaje_mujeres = n/Gran_Total * 100,
         Total_Porcentaje = sum(Porcentaje_mujeres))

datatable(rta_5)
r5 <- ggplot(data = rta_5, aes(x = ESTU_ESTUDIANTE, y = Porcentaje_mujeres)) +
        geom_bar(stat = "identity",
                 fill = c("gray15", "gray50"),
                 color = "red") + 
        geom_text(aes(label = round(Porcentaje_mujeres, digits = 1)),
                  size = 8,
                  color = c("white", "black"), 
                  position = position_stack(vjust = 0.5)) +
        labs(x = "Mujer",
             y = "Porcentaje de registros",
             main = "") + 
        theme_classic()

r5

6. ¿Qué porcentaje de estudiantes tienen una sola discapacidad (cualquiera)?

Motriz <- icfes %>%
  filter(ESTU_ESTUDIANTE == "ESTUDIANTE") %>%
  select(ESTU_LIMITA_AUTISMO, ESTU_LIMITA_CONDICIONESPECIAL, ESTU_LIMITA_MOTRIZ,
         ESTU_LIMITA_INVIDENTE, ESTU_LIMITA_SDOWN, ESTU_LIMITA_SORDO) %>%
  count(ESTU_LIMITA_MOTRIZ == "MOT" & ESTU_LIMITA_AUTISMO == "" &
          ESTU_LIMITA_CONDICIONESPECIAL == "" & ESTU_LIMITA_INVIDENTE == "" & 
          ESTU_LIMITA_SDOWN == "" & ESTU_LIMITA_SORDO == "") 

Invidente <- icfes %>%
  filter(ESTU_ESTUDIANTE == "ESTUDIANTE") %>%
  select(ESTU_LIMITA_AUTISMO, ESTU_LIMITA_CONDICIONESPECIAL, ESTU_LIMITA_MOTRIZ,
         ESTU_LIMITA_INVIDENTE, ESTU_LIMITA_SDOWN, ESTU_LIMITA_SORDO) %>%
  count(ESTU_LIMITA_MOTRIZ == "" & ESTU_LIMITA_AUTISMO == "" & 
          ESTU_LIMITA_CONDICIONESPECIAL == "" & ESTU_LIMITA_INVIDENTE == "VIS" & 
          ESTU_LIMITA_SDOWN == "" & ESTU_LIMITA_SORDO == "") 

Especial <- icfes %>%
  filter(ESTU_ESTUDIANTE == "ESTUDIANTE") %>%
  select(ESTU_LIMITA_AUTISMO, ESTU_LIMITA_CONDICIONESPECIAL, ESTU_LIMITA_MOTRIZ,
         ESTU_LIMITA_INVIDENTE, ESTU_LIMITA_SDOWN, ESTU_LIMITA_SORDO) %>%
  count(ESTU_LIMITA_MOTRIZ == "" & ESTU_LIMITA_AUTISMO == "" & 
          ESTU_LIMITA_CONDICIONESPECIAL == "CE" & ESTU_LIMITA_INVIDENTE == "" & 
          ESTU_LIMITA_SDOWN == "" & ESTU_LIMITA_SORDO == "")

Sordo <- icfes %>%
  filter(ESTU_ESTUDIANTE == "ESTUDIANTE") %>%
  select(ESTU_LIMITA_AUTISMO, ESTU_LIMITA_CONDICIONESPECIAL, ESTU_LIMITA_MOTRIZ,
         ESTU_LIMITA_INVIDENTE, ESTU_LIMITA_SDOWN, ESTU_LIMITA_SORDO) %>%
  count(ESTU_LIMITA_MOTRIZ == "" & ESTU_LIMITA_AUTISMO == "" & 
          ESTU_LIMITA_CONDICIONESPECIAL == "" & ESTU_LIMITA_INVIDENTE == "" & 
          ESTU_LIMITA_SDOWN == "" & ESTU_LIMITA_SORDO == "AUD")

SDown <- icfes %>%
  filter(ESTU_ESTUDIANTE == "ESTUDIANTE") %>%
  select(ESTU_LIMITA_AUTISMO, ESTU_LIMITA_CONDICIONESPECIAL, ESTU_LIMITA_MOTRIZ,
         ESTU_LIMITA_INVIDENTE, ESTU_LIMITA_SDOWN, ESTU_LIMITA_SORDO) %>%
  count(ESTU_LIMITA_MOTRIZ == "" & ESTU_LIMITA_AUTISMO == "" & 
        ESTU_LIMITA_CONDICIONESPECIAL == "" & 
        ESTU_LIMITA_INVIDENTE == "" & ESTU_LIMITA_SDOWN == "SD" & 
          ESTU_LIMITA_SORDO == "")

Autismo <- icfes %>%
  filter(ESTU_ESTUDIANTE == "ESTUDIANTE") %>%
  select(ESTU_LIMITA_AUTISMO, ESTU_LIMITA_CONDICIONESPECIAL, ESTU_LIMITA_MOTRIZ,
         ESTU_LIMITA_INVIDENTE, ESTU_LIMITA_SDOWN, ESTU_LIMITA_SORDO) %>%
  count(ESTU_LIMITA_MOTRIZ == "" & ESTU_LIMITA_AUTISMO == "AA" &
        ESTU_LIMITA_CONDICIONESPECIAL == "" & ESTU_LIMITA_INVIDENTE == "" & 
        ESTU_LIMITA_SDOWN == "" & ESTU_LIMITA_SORDO == "")

#Totales por discapacidad
discapacidad <- data.frame(Discapacidad = c(Motriz$n[2], Invidente$n[2], Especial$n[2],
                                            Sordo$n[2], SDown$n[2], Autismo$n[2]),
                           Tipo_Discapacidad = c("Motriz", "Invidente", "Especial",
                                                "Sordo", "SDown", "Autismo")) %>%
  mutate(Total = sum(Discapacidad))

pander(discapacidad)
Discapacidad Tipo_Discapacidad Total
478 Motriz 1016
154 Invidente 1016
10 Especial 1016
115 Sordo 1016
73 SDown 1016
186 Autismo 1016
r6 <- ggplot(data = discapacidad, aes(x = Tipo_Discapacidad, y = Discapacidad)) + 
  geom_bar(stat = "identity", fill = "gray15", color = "red") + 
  labs(x = "Tipo de discapacidad",
       y = "Número de registros") + 
  geom_text(aes(label = Discapacidad),
            position = position_dodge(1),
            vjust = -0.3,
            size = 6.5) + 
  theme_classic()

r6  

12. ¿Cuál de los departamentos de residencia posee mayor número de registros o pruebas en el año 2016-02?

rta_12 <- icfes %>%
  filter(ESTU_RESIDE_DEPTO != "" & ESTU_RESIDE_DEPTO != "EXTRANJERO") %>%
  group_by(ESTU_RESIDE_DEPTO) %>%
  count() %>%
  ungroup() %>%
  mutate(Total = sum(n),
         Porcentaje = n/Total * 100) %>%
  arrange(desc(n))

datatable(rta_12)
r12 <- ggplot(data = rta_12, aes(x = ESTU_RESIDE_DEPTO, y = n)) +
  geom_bar(stat = "identity", fill = "gray15", color = "red") + 
  labs(x = "Departamento de residencia",
       y = "Número de registros") +
  geom_text(aes(label = round(Porcentaje, digits = 1)),
            position = position_dodge(1),
            vjust = -0.3,
            size = 3.5) + 
  theme_classic() +
  theme(axis.text.x = element_text(angle = 90))

r12

20. Teniendo en cuenta que los registros corresponden al segundo semestre del año 2016 (2016-02), ¿cuántas personas terminaron el bachillerato hace más de 3 años?

rta_20 <- icfes %>%
  filter(ESTU_ANO_TERMINO_BACHILL < 2013 & ESTU_MES_TERMINO_BACHILL < 6) %>%
  count() %>%
  mutate(Total = 605982,
         Porcentaje = n/Total * 100)

pander(rta_20)
n Total Porcentaje
477 605982 0.07872

23. ¿Pagan pensiones más costosas hombres o mujeres?

rta_23 <- icfes %>%
  mutate(COLE_VALOR_PENSION = factor(COLE_VALOR_PENSION)) %>%
  filter(COLE_VALOR_PENSION != "" & ESTU_GENERO != "") %>%
  group_by(COLE_VALOR_PENSION, ESTU_GENERO) %>%
  count()

rta_23Por <- rta_23 %>%
  ungroup() %>%
  group_by(COLE_VALOR_PENSION) %>%
  mutate(Total = sum(n),
         Porcentaje = n/Total * 100)

pander(rta_23Por)
COLE_VALOR_PENSION ESTU_GENERO n Total Porcentaje
1 F 244459 438317 55.77
1 M 193858 438317 44.23
2 F 21349 42785 49.9
2 M 21436 42785 50.1
3 F 8486 18218 46.58
3 M 9732 18218 53.42
4 F 6461 12771 50.59
4 M 6310 12771 49.41
5 F 13583 25477 53.31
5 M 11894 25477 46.69
6 F 13997 27473 50.95
6 M 13476 27473 49.05
r23 <- ggplot(data = rta_23Por,
              aes(x = COLE_VALOR_PENSION, y = Porcentaje, fill = ESTU_GENERO)) + 
  geom_bar(stat = "identity", color = "red") + 
  scale_fill_manual(values = c("gray10", "gray40")) + 
  scale_color_manual(values = "red") +
  geom_text(aes(label = round(Porcentaje, digits = 1)),
            size = 8,
            position = position_stack(vjust = 0.5),
            col = "white") +
  labs(x = "Valor de la pensión",
       y = "Porcentaje de registros",
       fill = "Género") + 
  theme_classic()

r23

27. ¿Cuáles son los cinco departamentos con mayor número de estudiantes que laboran?

rta_27 <- icfes %>%
  mutate(ESTU_TRABAJA = factor(ESTU_TRABAJA)) %>%
  filter(ESTU_ESTUDIANTE == "ESTUDIANTE" & ESTU_TRABAJA != "" & ESTU_TRABAJA != "1") %>%
  group_by(ESTU_RESIDE_DEPTO, ESTU_TRABAJA) %>%
  count()

rta_27Por <- rta_27 %>%
  ungroup() %>%
  group_by(ESTU_RESIDE_DEPTO) %>%
  mutate(Total = sum(n),
         Porcentaje = n/Total * 100) %>%
  arrange(desc(Porcentaje))

datatable(rta_27Por)
r27 <- ggplot(data = rta_27Por,
              aes(x = ESTU_RESIDE_DEPTO, y = Porcentaje, fill = ESTU_TRABAJA)) + 
  geom_bar(stat = "identity", color = "red") + 
  scale_fill_manual(values = c("gray10", "gray40")) + 
  scale_color_manual(values = "red") +
  labs(x = "Departamento de residencia",
       y = "Porcentaje de registros",
       fill = "¿Trabaja?") + 
  theme_classic() +
   theme(axis.text.x = element_text(angle = 90))

r27