df_dens <- bind_rows(
datos %>% select(der_matricula) %>% mutate(Tipo = "Poblacion"),
muestra_mas %>% select(der_matricula) %>% mutate(Tipo = "MAS"),
muestra_sist %>% select(der_matricula) %>% mutate(Tipo = "Sistematico"),
muestra_conv %>% select(der_matricula) %>% mutate(Tipo = "No Probabilistico"),
muestra_estrat %>% select(der_matricula) %>% mutate(Tipo = "Estratificado"),
muestra_cong_1e %>% select(der_matricula) %>% mutate(Tipo = "Cong. 1 etapa"),
muestra_cong_2e %>% select(der_matricula) %>% mutate(Tipo = "Cong. 2 etapas")
)
df_dens$Tipo <- factor(df_dens$Tipo,
levels = c("Poblacion", "MAS", "Sistematico", "No Probabilistico",
"Estratificado", "Cong. 1 etapa", "Cong. 2 etapas"))
p_plotly <-
ggplot(df_dens, aes(x = der_matricula, color = Tipo)) +
geom_density(linewidth = 0.8) +
scale_color_manual(values = c("black", colores_metodos)) +
geom_vline(xintercept = 500000, color = "red", linetype = "dotted", linewidth = 0.7) +
geom_vline(xintercept = mu_real, color = "#e67e22", linetype = "dashed", linewidth = 0.7) +
scale_x_continuous(labels = label_number(big.mark = ".", scale = 1e-3, suffix = "k", prefix = "$")) +
labs(title = "Distribucion de Matriculas: Poblacion vs Muestras (6 metodos)",
x = "Derecho de Matricula", y = "Densidad") +
theme_minimal(base_size = 13) +
theme(plot.title = element_text(face = "bold"))
ggplotly(p_plotly) %>%
layout(margin = list(t = 80)) %>%
add_annotations(
x = 500000, y = 0.65, yref = "paper",
text = "Medio SMMLV<br>$500.000",
showarrow = TRUE, arrowhead = 2, arrowcolor = "red",
font = list(color = "red", size = 11),
ax = 150, ay = 0,
xref = "x"
) %>%
add_annotations(
x = mu_real, y = 0.45, yref = "paper",
text = paste0("μ real<br>$", format(round(mu_real), big.mark = ".")),
showarrow = TRUE, arrowhead = 2, arrowcolor = "#e67e22",
font = list(color = "#e67e22", size = 11),
ax = 150, ay = 0,
xref = "x"
) %>%
config(displaylogo = FALSE)