rm(list=ls())
gc()
##          used (Mb) gc trigger (Mb) max used (Mb)
## Ncells 503802 27.0    1117312 59.7   644242 34.5
## Vcells 888015  6.8    8388608 64.0  1635170 12.5
ls()
## character(0)
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.2.3
library(gridExtra)
## Warning: package 'gridExtra' was built under R version 4.2.3
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:gridExtra':
## 
##     combine
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(readxl)
## Warning: package 'readxl' was built under R version 4.2.3
data <- read_excel("C:/Users/Julietha Zorro M/Downloads/Análisis de la Brecha de Acceso y Calidad entre Instituciones Educativas Públicas y Privadas en Bogotá.xlsx")
View(data)

El código usado por los estudiantes es:

ggplot(data, aes(x = Género, fill = Discriminación)) +
  geom_bar(position = "dodge") +
  labs(x = "Género", y = "Count", fill = "Discriminación") +
  ggtitle("Relación entre Género y Discriminación") +
  theme_minimal()

ggplot(data, aes(x = `Tipo de Institución`, y = Localidad)) +
  geom_jitter(width = 0.2, height = 0.2, alpha = 0.5) +
  labs(x = "Tipo de Institución", y = "Localidad") +
  ggtitle("Relación entre Tipo de Institución y Localidad") +
  theme_minimal()

Se ajusta el codigo de la última gráfica, es necesario agrupar según nombre de la localidad.

Nota: Restrepo no es una localidad

table(data$Localidad)
## 
##    02, chapinero   Antonio nariño   Antonio Nariño   Barrios unidos 
##                1                1                1                1 
##        Chapinero             Chía   Ciudad bolivar      El Restrepo 
##                6                1                1                1 
##         Restrepo         Santa fe         Santa Fe Suba (Arrayanes) 
##                1                1                1                1 
##      Teusaquillo          Usaquen          Usaquén 
##                3                1                1
data <- data %>%
  mutate(Localidad_aju = case_when(Localidad %in% c("02, chapinero","Chapinero") ~ "Chapinero", 
                                   Localidad %in% c("Antonio nariño","Antonio Nariño") ~ "Antonio Nariño",
         Localidad %in% c("El Restrepo","Restrepo") ~"Restrepo",
         Localidad %in% c("Santa fe","Santa Fe") ~ "Santa Fe",
         Localidad %in% c("Usaquen","Usaquén") ~ "Usaquén",
         T ~ Localidad))

table(data$Localidad,data$Localidad_aju)
##                   
##                    Antonio Nariño Barrios unidos Chapinero Chía Ciudad bolivar
##   02, chapinero                 0              0         1    0              0
##   Antonio nariño                1              0         0    0              0
##   Antonio Nariño                1              0         0    0              0
##   Barrios unidos                0              1         0    0              0
##   Chapinero                     0              0         6    0              0
##   Chía                          0              0         0    1              0
##   Ciudad bolivar                0              0         0    0              1
##   El Restrepo                   0              0         0    0              0
##   Restrepo                      0              0         0    0              0
##   Santa fe                      0              0         0    0              0
##   Santa Fe                      0              0         0    0              0
##   Suba (Arrayanes)              0              0         0    0              0
##   Teusaquillo                   0              0         0    0              0
##   Usaquen                       0              0         0    0              0
##   Usaquén                       0              0         0    0              0
##                   
##                    Restrepo Santa Fe Suba (Arrayanes) Teusaquillo Usaquén
##   02, chapinero           0        0                0           0       0
##   Antonio nariño          0        0                0           0       0
##   Antonio Nariño          0        0                0           0       0
##   Barrios unidos          0        0                0           0       0
##   Chapinero               0        0                0           0       0
##   Chía                    0        0                0           0       0
##   Ciudad bolivar          0        0                0           0       0
##   El Restrepo             1        0                0           0       0
##   Restrepo                1        0                0           0       0
##   Santa fe                0        1                0           0       0
##   Santa Fe                0        1                0           0       0
##   Suba (Arrayanes)        0        0                1           0       0
##   Teusaquillo             0        0                0           3       0
##   Usaquen                 0        0                0           0       1
##   Usaquén                 0        0                0           0       1
table(is.na(data$Localidad_aju))
## 
## FALSE 
##    22
names(data)
##  [1] "Nombre"                       "Edad"                        
##  [3] "Género"                       "Tipo de Institución"         
##  [5] "Localidad"                    "Infraestructura física"      
##  [7] "Capacitación de los docentes" "Hipótesis"                   
##  [9] "Discriminación"               "Tecnológia"                  
## [11] "Influencia"                   "Diferencias significativas"  
## [13] "Localidad_aju"
Ins <- data %>%
  select(`Tipo de Institución`,Localidad_aju)%>%
  group_by(`Tipo de Institución`,Localidad_aju)%>%
  summarise(Total=n())
## `summarise()` has grouped output by 'Tipo de Institución'. You can override
## using the `.groups` argument.
names(Ins)  
## [1] "Tipo de Institución" "Localidad_aju"       "Total"
# Ordenar el dataframe según el valor de personas de manera descendente
P <- Ins %>%
  filter(`Tipo de Institución` =="Privada")%>%
  arrange(desc(ifelse(`Tipo de Institución` =="Privada", Total, NA)))

# Convertir la variable Localidad_aju en un factor con el orden deseado
Ins$Localidad_aju <- factor(Ins$Localidad_aju, levels = P$Localidad_aju)



plot3 <- ggplot(Ins, aes(x = Localidad_aju, y = Total))+
  geom_bar(stat = "identity", fill = "cadetblue") +
  labs(title = "Nombre xxxx",
       subtitle = "Año xxx",
       caption = "Fuente: xxx?¿",
       x = "Localidad",
       y = "Personasxxx")+
  geom_text(aes(label = Total), vjust = -0.5, color = "black", size = 2) +  # Agrega etiquetas de texto
  theme_light()+
  theme(axis.text.x = element_text(angle = 45, hjust = 1,size=5.5))+
  facet_grid(`Tipo de Institución` ~ .)

plot3

Boxplot ajustado:

names(Ins)
## [1] "Tipo de Institución" "Localidad_aju"       "Total"
box <- ggplot(data=Ins,aes(x=`Tipo de Institución`,y=Total,)) +
  geom_boxplot() +
  geom_jitter(color="black", size=0.4, alpha=0.9) +
  theme(
    legend.position="none",
    plot.title = element_text(size=11)
  ) +
  ggtitle("Boxplot") +
  xlab("")

box