-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03_tables-and-figures.R
184 lines (158 loc) · 7.76 KB
/
03_tables-and-figures.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# Tablas y figuras del artículo principal
# General settings -------------------------------------------------------------
AUX$colores <- c("#7CAE00", "#00BFC4", "#F8766D", "#C77CFF")
TAB <- list()
# Figuras ------------------------------------
# Figure 01: Descripción de variables --------------------------------------
d2 <- data.frame(SEC_MFA$quanti.var$coord,
CONTR = SEC_MFA$quanti.var$contrib[ ,1:2],
SEC_MFA$summary.quanti |>
select(group, variable) |>
filter(group %in% 1:3) ) %>%
mutate(group = factor(group, levels = 1:3,
labels = c("Origen", "Rendimiento",
"Homogeneidad")),
CONTR = CONTR.Dim.1 + CONTR.Dim.2) %>%
group_by(group) %>%
mutate(m = mean(CONTR))
p <- fviz_mfa_var(SEC_MFA, choice = c("quanti.var"), alpha.var = 0,
geom = "arrow", col.var.sup = NA, title = "") +
geom_segment(data = d2,
aes(xend = Dim.1, yend = Dim.2,
colour = factor(group)),
x = 0, y = 0,
arrow = arrow(angle = 25, length = unit(0.25, "cm") ) ) +
geom_text_repel(data = d2, #%>% filter(CONTR > m),
aes(x = Dim.1, y = Dim.2, label = variable),
size = 3, colour = "black") +
facet_grid(cols = vars(group)) +
scale_color_discrete("Dimensión de análisis") +
# labs(caption = "Fuente: Elaboración propia.") +
theme(legend.position = "none",
strip.text.x = element_text(size = 16))
ggsave(filename = here::here("analysis/figures/01_variables.png"),
plot = p,
width = 30, height = 12, units = "cm")
rm(d2, p)
# Figure 02: Escuelas por cluster ----------------------------------------------
dat <- bind_cols(SEC_MFA$ind$coord |> data.frame(),
SEC_aux |> select(cl, cl_p, SECTOR))
subp <- fviz_mfa_var(SEC_MFA, choice = c("quanti.var"), geom = "arrow",
axes = c(1,2), title = "Variables de análisis", ) +
theme_void() +
theme(legend.position = "none",
plot.title = element_text(hjust = 0.5) )
p <- fviz_mfa_var(SEC_MFA, col.var = NA, col.var.sup = NA, title = "" ) +
geom_point(data = dat |> filter(cl_p >= 0.5),
mapping = aes(x = Dim.1, y = Dim.2,
color = cl, shape = SECTOR)) +
geom_point(data = dat |> filter(cl_p < 0.5),
mapping = aes(x = Dim.1, y = Dim.2,
shape = SECTOR), color = "grey70") +
geom_point(data = data.frame(CLUSTER$H) |> add_row(), shape = 23,
mapping = aes(x = Dim.1, y = Dim.2,
fill = factor(c(1:4, "Sin asignar"))),
color = "black", size = 3) +
scale_color_manual(values = AUX$colores) +
scale_shape("Sector", solid = T) +
scale_fill_manual("Clúster", values = c(AUX$colores, "grey70")) +
theme(legend.position = "bottom",
legend.direction = "vertical",
legend.margin = margin(0, 0.8, 0, 0.8, unit="cm")) +
guides(shape = guide_legend(order = 1),
fill = guide_legend(order = 2,
direction = "horizontal",
nrow = 2,
title.position = "top"),
color = "none") +
annotation_custom(grob = ggplotGrob(subp),
ymin = 2, ymax = 4.5, xmin = -3, xmax = -0.5)
ggsave(filename = here::here("analysis/figures/02_esc-x-cluster.png"),
plot = p,
width = 30, height = 25, units = "cm")
rm(p, subp, dat)
# Tablas -------------------------------------
# Table 01: Descripción clúster ----------------------------------------------
TAB$t1 <- CLUSTER$Descrip %>%
mutate(cl = paste("Clúster", cl),
P.Asig = round(P.Asig, 1),
blank1 = NA,
blank2 = NA) %>%
select(cl, Cl.Size:Cl.Student, blank1,
No.Asig:P.Asig, blank2,
starts_with("deg.")) |>
flextable() |>
set_caption(caption = "Descripción general del resultado de los agrupamientos",
autonum = run_autonum(seq_id = "tab",
bkm = "FUZZY",
bkm_all = T)) |>
colformat_double(j = 8:10, digits = 2) %>%
colformat_double(j = 6, digits = 1) %>%
set_header_labels(cl = " ", Cl.Size = "Escuelas",
Cl.Student = "Estudiantes", blank1 = "",
No.Asig = "Total", P.Asig = "%", blank2 = "",
deg.Min = "Mínimo", deg.Max = "Máximo", deg.Av = "Promedio") |>
add_header_row(colwidths = c(1, 2, 1, 2, 1, 3),
values = c(" ", "Tamaño del clúster", "",
"Escuelas difusas", "",
"Probabilidad de asignación") ) |>
merge_h(part = "header") |>
merge_v(part = "header") |>
align(j = -1, align = "center", part = "all") |>
align(j = 1, align = "left", part = "all") |>
color(j = c("deg.Min", "deg.Max", "deg.Av"),
color = "#9F9F9F", part = "all") |>
autofit() |>
add_footer_lines(value = paste("Coeficiente de Partición Modificado (MPC)",
round(CLUSTER$Index["MPC"], 3),
sep = ": ")
)
# Tabla 02: Alumnos por sector y clúster ----------------------------------
TAB$t2 <- CLUSTER$Tab_Sec |>
flextable() |>
set_caption(caption = "Cantidad de Alumnos por Clústers según sector de gestión",
autonum = run_autonum(seq_id = "tab",
bkm = "CL-SECTOR",
bkm_all = T)) |>
set_header_labels(Circuito = " ", Privado = "Global",
SI = "Subsidiada", NO = "Independiente") |>
add_header_row(colwidths = c(1, 1, 3, 1),
values = c(" ", "Estatal", "Privada", "Total") ) |>
merge_h(part = "header") |>
merge_v(part = "header") |>
align(j = 2:6, align = "center", part = "all") |>
color(j = 4:5, color = "#9F9F9F", part = "all") |>
add_footer_lines(value = c(paste0("Versión Fuzzy del Índice de ",
c("Rand", "Jaccard"), ": ",
CLUSTER$Ind_Sec[-2]) ) ) |>
autofit()
# Tabla 03: Segregación según modelo ---------------------------------------
TAB$t3 <- SEGRE$t_f |>
flextable() |>
set_caption(caption = "Porcentaje de segregación explicada por diferencia inter- e intra- grupo según modelo de agrupamiento",
autonum = run_autonum(seq_id = "tab",
bkm = "SEGRE1",
bkm_all = T)) |>
set_header_labels(I = "Modelo de agrupamiento",
Prop_ENTRE = "Inter-grupo",
Prop_DENTRO = "Intra-grupo") |>
add_header_row(colwidths = c(1, 2),
values = c("Modelo de agrupamiento", "Proporción (%)") ) |>
merge_v(part = "header") |>
align(j = 2:3, align = "center", part = "all") |>
autofit()
# Tabla 04: Segregación local -inter e -intra --------------------------------
TAB$t4 <- SEGRE$t_l %>%
select(-p) |>
flextable() |>
set_caption(caption = "Segregación local -inter e -intra clúster",
autonum = run_autonum(seq_id = "tab",
bkm = "SEGRE2",
bkm_all = T)) |>
set_header_labels(cl = "Clúster") |>
add_header_row(colwidths = c(1, 2),
values = c("Clúster", "Mutual Index Local") ) |>
merge_v(part = "header") |>
align(j = 2:3, align = "center", part = "all") |>
colformat_double(digits = 3) |>
autofit()