- Procesos de Normalización y Limpieza
- Panorama General
- Hallazgos y Recomendaciones
Junio 2020
Los esfuerzos se han centrado en:
a=nrow(CONS_C1_df_dup_JUL_2020) b=nrow(CONS_C1_df_dup)-nrow(CONS_C1_df_dup_ENE_2020_prev) c=nrow(CONS_C1_df_dup_ENE_2020_prev)-nrow(CONS_C1_df_dup_ENE_2020_prev2) d=nrow(CONS_C1_df_dup_ENE_2020)-nrow(CONS_C1_df_dup_FEB_2020) b_c_d=b+c+d e=nrow(CONS_C1_df_dup_FEB_2020)-nrow(CONS_C1_df_dup_JUL_2020) dt<- data.frame(cbind(id=c("Total de Tratamientos"), value=as.numeric(c(b_c_d,e,a)), parent=c("Entradas Duplicadas", "Entradas correspondientes a eventos\nintermedios de tratamiento", "Tratamientos diferenciados por usuario") )) dt<- dt %>% dplyr::mutate(value=as.numeric(value), percent=paste0(round(100 * value/sum(value), 0), "%"), Categoría=paste0(parent,"\n",percent))
percent <- function(x, digits = 2, format = "f", ...) { paste0(formatC(100 * x, format = format, digits = digits, ...), "%") } p<- plotly::plot_ly(dt, labels = ~parent, values = ~value, type = 'pie',hole = 0.3,textposition = 'outside',textinfo = 'label+percent', marker = list(colors = c("hotpink4","cornsilk","lightgrey","darkgoldenrod","mediumpurple"))) %>% layout(xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE), yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))%>% layout(legend = list(orientation = 'h',yanchor='top',xanchor='center',y=0,x=.5)) plotly_IMAGE(p, width = 1500, height = 500, format = "png", scale = 2,dpi=700, out_file = "G:/Mi unidad/Alvacast/SISTRAT 2019 (github)/Presentación a SENDA Jun 2020/test.png") p
i<- "senda" casos_no_cubiertos<- CONS_C1_df_dup_MAY_2020_prev_5 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt<2009) %>% dplyr::ungroup()%>% summarise(sum_total=sum(n_2_grupos))%>% unlist() CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt>=2009) %>% ggplot2::ggplot(aes(x = fech_ing_qrt, y = freq,fill=grupo_var))+ geom_area(alpha=0.6 , size=.5, colour="white") + scale_fill_viridis(discrete = T, direction = -1) + sjPlot::theme_sjplot2() + scale_x_yearqtr(format="%YQ%q", n=18, limits=c(zoo::as.yearqtr("2009-04-01"), max=zoo::as.yearqtr("2019-11-13")))+ scale_y_continuous(limits=c(0,1),labels = scales::percent)+ labs(x="",y="Porcentajes", caption= paste0("Nota. Se ignoraron ", casos_no_cubiertos, " casos con una fecha de admisión anterior al año 2009;\n", "Porcentajes por año y trimestre"))+ #ylim(0,101)+ # scale_y_continuous(limits=c(0,1),labels = scales::percent) + theme(legend.position="bottom")+ guides(fill=guide_legend(ncol=3))+ theme(legend.text = element_text(size=10))+ theme(legend.title = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), panel.grid.major.x = element_blank(), panel.background = element_blank(), axis.title.x = element_blank())+ theme(axis.text.x = element_text(vjust = 0.5,hjust = 0.5,angle = 60), plot.caption=element_text(hjust=0))
if(isTRUE(getOption('knitr.in.progress'))==T){ } else {ggsave(paste0(i,".png"),dpi=320)}
## NULL
i<- "escolaridad_rec" casos_no_cubiertos<- CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt<2009) %>% dplyr::ungroup()%>% summarise(sum_total=sum(n_2_grupos))%>% unlist() CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt>=2009) %>% ggplot2::ggplot(aes(x = fech_ing_qrt, y = freq,fill=grupo_var))+ geom_area(alpha=0.6 , size=.5, colour="white") + scale_fill_viridis(discrete = T) + sjPlot::theme_sjplot2() + scale_x_yearqtr(format="%YQ%q", n=18, limits=c(zoo::as.yearqtr("2009-04-01"), max=zoo::as.yearqtr("2019-11-13")))+ scale_y_continuous(limits=c(0,1),labels = scales::percent)+ labs(x="",y="Porcentajes", caption= paste0("Nota. Se ignoraron ", casos_no_cubiertos, " casos con una fecha de admisión anterior al año 2009;\n", "Porcentajes por año y trimestre"))+ #ylim(0,101)+ # scale_y_continuous(limits=c(0,1),labels = scales::percent) + theme(legend.position="bottom")+ guides(fill=guide_legend(ncol=3))+ theme(legend.text = element_text(size=10))+ theme(legend.title = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), panel.grid.major.x = element_blank(), panel.background = element_blank(), axis.title.x = element_blank())+ theme(axis.text.x = element_text(vjust = 0.5,hjust = 0.5,angle = 60), plot.caption=element_text(hjust=0))
if(isTRUE(getOption('knitr.in.progress'))==T){ } else {ggsave(paste0(i,".png"),dpi=320)}
NULL
i<- "estado_conyugal_2" casos_no_cubiertos<- CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt<2009) %>% dplyr::ungroup()%>% summarise(sum_total=sum(n_2_grupos))%>% unlist() CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt>=2009) %>% ggplot2::ggplot(aes(x = fech_ing_qrt, y = freq,fill=grupo_var))+ geom_area(alpha=0.6 , size=.5, colour="white") + scale_fill_viridis(discrete = T) + scale_y_continuous(limits=c(0,1),labels = scales::percent)+ sjPlot::theme_sjplot2() + scale_x_yearqtr(format="%YQ%q", n=18, limits=c(zoo::as.yearqtr("2009-04-01"), max=zoo::as.yearqtr("2019-11-13")))+ labs(x="",y="Porcentajes", caption= paste0("Nota. Se ignoraron ", casos_no_cubiertos, " casos con una fecha de admisión anterior al año 2009;\n", "Porcentajes por año y trimestre"))+ #ylim(0,101)+ # scale_y_continuous(limits=c(0,1),labels = scales::percent) + theme(legend.position="bottom")+ guides(fill=guide_legend(ncol=3))+ theme(legend.text = element_text(size=10))+ theme(legend.title = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), panel.grid.major.x = element_blank(), panel.background = element_blank(), axis.title.x = element_blank())+ theme(axis.text.x = element_text(vjust = 0.5,hjust = 0.5,angle = 60), plot.caption=element_text(hjust=0))
if(isTRUE(getOption('knitr.in.progress'))==T){ } else {ggsave(paste0(i,".png"),dpi=320)}
## NULL
i<- "origen_ingreso_mod" casos_no_cubiertos<- CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt<2009) %>% dplyr::ungroup()%>% summarise(sum_total=sum(n_2_grupos))%>% unlist() CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt>=2009) %>% ggplot2::ggplot(aes(x = fech_ing_qrt, y = freq,fill=grupo_var))+ geom_area(alpha=0.6 , size=.5, colour="white") + scale_fill_viridis(discrete = T) + sjPlot::theme_sjplot2() + scale_y_continuous(limits=c(0,1),labels = scales::percent)+ scale_x_yearqtr(format="%YQ%q", n=18, limits=c(zoo::as.yearqtr("2009-04-01"), max=zoo::as.yearqtr("2019-11-13")))+ labs(x="",y="Porcentajes", caption= paste0("Nota. Se ignoraron ", casos_no_cubiertos, " casos con una fecha de admisión anterior al año 2009;\n", "Porcentajes por año y trimestre"))+ #ylim(0,101)+ # scale_y_continuous(limits=c(0,1),labels = scales::percent) + theme(legend.position="bottom")+ guides(fill=guide_legend(ncol=3))+ theme(legend.text = element_text(size=10))+ theme(legend.title = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), panel.grid.major.x = element_blank(), panel.background = element_blank(), axis.title.x = element_blank())+ theme(axis.text.x = element_text(vjust = 0.5,hjust = 0.5,angle = 60), plot.caption=element_text(hjust=0))
if(isTRUE(getOption('knitr.in.progress'))==T){ } else {ggsave(paste0(i,".png"),dpi=320) }
## NULL
i<- "motivodeegreso_mod_imp" # geom_vline(xintercept = 60, color="darkred", size=1.5) casos_no_cubiertos<- CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt<2009|fech_ing_qrt>=2016.5) %>% dplyr::ungroup()%>% summarise(sum_total=sum(n_2_grupos))%>% unlist() CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt>=2009,fech_ing_qrt<2016.5) %>% ggplot2::ggplot(aes(x = fech_ing_qrt, y = freq,fill=grupo_var))+ geom_area(alpha=0.6 , size=.5, colour="white") + scale_fill_viridis(discrete = T) + sjPlot::theme_sjplot2() + scale_y_continuous(limits=c(0,1),labels = scales::percent)+ scale_x_yearqtr(format="%YQ%q", n=18, limits=c(zoo::as.yearqtr("2009-04-01"), max=zoo::as.yearqtr("2016-06-30")))+ labs(x="",y="Porcentajes", caption= paste0("Nota. Se ignoraron ", formatC(casos_no_cubiertos, big.mark=","), " casos con una fecha de admisión anterior al año 2009\n", "y posterior al segundo semestre del 2016; Porcentajes por año y trimestre"))+ #ylim(0,101)+ # scale_y_continuous(limits=c(0,1),labels = scales::percent) + theme(legend.position="bottom")+ guides(fill=guide_legend(ncol=3))+ theme(legend.text = element_text(size=10))+ theme(legend.title = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), panel.grid.major.x = element_blank(), panel.background = element_blank(), axis.title.x = element_blank())+ theme(axis.text.x = element_text(vjust = 0.5,hjust = 0.5,angle = 60), plot.caption=element_text(hjust=0))+ geom_vline(xintercept = zoo::as.yearqtr("2016-06-01"), color="darkred", size=1.5)
if(isTRUE(getOption('knitr.in.progress'))==T){ } else {ggsave(paste0(i,".png"),dpi=320)}
## NULL
i<- "motivodeegreso_mod_imp" # geom_vline(xintercept = 60, color="darkred", size=1.5) casos_no_cubiertos<- CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt<2016.5) %>% dplyr::ungroup()%>% summarise(sum_total=sum(n_2_grupos))%>% unlist() CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt>=2016.5)%>% #dplyr::ungroup()%>% #summarise(sum_total=sum(n_2_grupos))%>% #unlist() ggplot2::ggplot(aes(x = fech_ing_qrt, y = freq,fill=grupo_var))+ geom_area(alpha=0.6 , size=.5, colour="white") + scale_fill_viridis(discrete = T) + sjPlot::theme_sjplot2() + scale_y_continuous(limits=c(0,1),labels = scales::percent)+ scale_x_yearqtr(format="%YQ%q", n=18, limits=c(zoo::as.yearqtr("2016-07-01"), max=zoo::as.yearqtr("2019-11-13")))+ labs(x="",y="Porcentajes", caption= paste0("Nota. Se ignoraron ", formatC(casos_no_cubiertos, big.mark=","), " casos con una fecha de admisión anterior al tercer semestre del año 2016;\n", "Porcentajes por año y trimestre"))+ #ylim(0,101)+ # scale_y_continuous(limits=c(0,1),labels = scales::percent) + theme(legend.position="bottom")+ guides(fill=guide_legend(ncol=3))+ theme(legend.text = element_text(size=10))+ theme(legend.title = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), panel.grid.major.x = element_blank(), panel.background = element_blank(), axis.title.x = element_blank())+ theme(axis.text.x = element_text(vjust = 0.5,hjust = 0.5,angle = 60), plot.caption=element_text(hjust=0))+ geom_vline(xintercept = zoo::as.yearqtr("2016-06-01"), color="darkred", size=1.5)
if(isTRUE(getOption('knitr.in.progress'))==T){ } else {ggsave(paste0(i,"_2.png"),dpi=320)}
## NULL
i<- "sexo_2" casos_no_cubiertos<- CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt<2009) %>% dplyr::ungroup()%>% summarise(sum_total=sum(n_2_grupos))%>% unlist() CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt>=2009) %>% ggplot2::ggplot(aes(x = fech_ing_qrt, y = freq,fill=grupo_var))+ geom_area(alpha=0.6 , size=.5, colour="white") + scale_fill_viridis(discrete = T) + sjPlot::theme_sjplot2() + scale_y_continuous(limits=c(0,1),labels = scales::percent)+ scale_x_yearqtr(format="%YQ%q", n=18, limits=c(zoo::as.yearqtr("2009-04-01"), max=zoo::as.yearqtr("2019-11-13")))+ labs(x="",y="Porcentajes", caption= paste0("Nota. Se ignoraron ", casos_no_cubiertos, " casos con una fecha de admisión anterior al año 2009;\n", "Porcentajes por año y trimestre"))+ #ylim(0,101)+ # scale_y_continuous(limits=c(0,1),labels = scales::percent) + theme(legend.position="bottom")+ guides(fill=guide_legend(ncol=3))+ theme(legend.text = element_text(size=10))+ theme(legend.title = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), panel.grid.major.x = element_blank(), panel.background = element_blank(), axis.title.x = element_blank())+ theme(axis.text.x = element_text(vjust = 0.5,hjust = 0.5,angle = 60), plot.caption=element_text(hjust=0))
if(isTRUE(getOption('knitr.in.progress'))==T){ } else {ggsave(paste0(i,".png"),dpi=320)}
## NULL
i<- "sus_ini_mod" casos_no_cubiertos<- CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt<2009) %>% dplyr::ungroup()%>% summarise(sum_total=sum(n_2_grupos))%>% unlist() CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt>=2009) %>% ggplot2::ggplot(aes(x = fech_ing_qrt, y = freq,fill=grupo_var))+ geom_area(alpha=0.6 , size=.5, colour="white") + scale_fill_viridis(discrete = T) + sjPlot::theme_sjplot2() + scale_y_continuous(limits=c(0,1),labels = scales::percent)+ scale_x_yearqtr(format="%YQ%q", n=18, limits=c(zoo::as.yearqtr("2009-04-01"), max=zoo::as.yearqtr("2019-11-13")))+ labs(x="",y="Porcentajes", caption= paste0("Nota. Se ignoraron ", casos_no_cubiertos, " casos con una fecha de admisión anterior al año 2009;\n", "Porcentajes por año y trimestre"))+ #ylim(0,101)+ # scale_y_continuous(limits=c(0,1),labels = scales::percent) + theme(legend.position="bottom")+ guides(fill=guide_legend(ncol=3))+ theme(legend.text = element_text(size=10))+ theme(legend.title = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), panel.grid.major.x = element_blank(), panel.background = element_blank(), axis.title.x = element_blank())+ theme(axis.text.x = element_text(vjust = 0.5,hjust = 0.5,angle = 60), plot.caption=element_text(hjust=0))
if(isTRUE(getOption('knitr.in.progress'))==T){ } else {ggsave(paste0(i,".png"),dpi=320)}
## NULL
i<- "sus_principal_mod" casos_no_cubiertos<- CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt<2009) %>% dplyr::ungroup()%>% summarise(sum_total=sum(n_2_grupos))%>% unlist() CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt>=2009) %>% ggplot2::ggplot(aes(x = fech_ing_qrt, y = freq,fill=grupo_var))+ geom_area(alpha=0.6 , size=.5, colour="white") + scale_fill_viridis(discrete = T) + sjPlot::theme_sjplot2() + scale_y_continuous(limits=c(0,1),labels = scales::percent)+ scale_x_yearqtr(format="%YQ%q", n=18, limits=c(zoo::as.yearqtr("2009-04-01"), max=zoo::as.yearqtr("2019-11-13")))+ labs(x="",y="Porcentajes", caption= paste0("Nota. Se ignoraron ", casos_no_cubiertos, " casos con una fecha de admisión anterior al año 2009;\n", "Porcentajes por año y trimestre"))+ #ylim(0,101)+ # scale_y_continuous(limits=c(0,1),labels = scales::percent) + theme(legend.position="bottom")+ guides(fill=guide_legend(ncol=3))+ theme(legend.text = element_text(size=10))+ theme(legend.title = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), panel.grid.major.x = element_blank(), panel.background = element_blank(), axis.title.x = element_blank())+ theme(axis.text.x = element_text(vjust = 0.5,hjust = 0.5,angle = 60), plot.caption=element_text(hjust=0))
if(isTRUE(getOption('knitr.in.progress'))==T){ } else {ggsave(paste0(i,".png"),dpi=320)}
## NULL
i<- "tipo_de_plan_2" casos_no_cubiertos<- CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt<2009) %>% dplyr::ungroup()%>% summarise(sum_total=sum(n_2_grupos))%>% unlist() CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt>=2009) %>% ggplot2::ggplot(aes(x = fech_ing_qrt, y = freq,fill=grupo_var))+ geom_area(alpha=0.6 , size=.5, colour="white") + scale_fill_viridis(discrete = T) + sjPlot::theme_sjplot2() + scale_y_continuous(limits=c(0,1),labels = scales::percent)+ scale_x_yearqtr(format="%YQ%q", n=18, limits=c(zoo::as.yearqtr("2009-04-01"), max=zoo::as.yearqtr("2019-11-13")))+ labs(x="",y="Porcentajes", caption= paste0("Nota. Se ignoraron ", casos_no_cubiertos, " casos con una fecha de admisión anterior al año 2009;\n", "Porcentajes por año y trimestre"))+ #ylim(0,101)+ # scale_y_continuous(limits=c(0,1),labels = scales::percent) + theme(legend.position="bottom")+ guides(fill=guide_legend(ncol=3))+ theme(legend.text = element_text(size=10))+ theme(legend.title = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), panel.grid.major.x = element_blank(), panel.background = element_blank(), axis.title.x = element_blank())+ theme(axis.text.x = element_text(vjust = 0.5,hjust = 0.5,angle = 60), plot.caption=element_text(hjust=0))
if(isTRUE(getOption('knitr.in.progress'))==T){ } else {ggsave(paste0(i,".png"),dpi=320)}
## NULL
i<- "freq_cons_sus_prin" casos_no_cubiertos<- CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt<2009) %>% dplyr::ungroup()%>% summarise(sum_total=sum(n_2_grupos))%>% unlist() CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=get(i))%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt>=2009) %>% ggplot2::ggplot(aes(x = fech_ing_qrt, y = freq,fill=grupo_var))+ geom_area(alpha=0.6 , size=.5, colour="white") + scale_fill_viridis(discrete = T) + sjPlot::theme_sjplot2() + scale_y_continuous(limits=c(0,1),labels = scales::percent)+ scale_x_yearqtr(format="%YQ%q", n=18, limits=c(zoo::as.yearqtr("2009-04-01"), max=zoo::as.yearqtr("2019-11-13")))+ labs(x="",y="Porcentajes", caption= paste0("Nota. Se ignoraron ", casos_no_cubiertos, " casos con una fecha de admisión anterior al año 2009;\n", "Porcentajes por año y trimestre"))+ #ylim(0,101)+ # scale_y_continuous(limits=c(0,1),labels = scales::percent) + theme(legend.position="bottom")+ guides(fill=guide_legend(ncol=3))+ theme(legend.text = element_text(size=10))+ theme(legend.title = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), panel.grid.major.x = element_blank(), panel.background = element_blank(), axis.title.x = element_blank())+ theme(axis.text.x = element_text(vjust = 0.5,hjust = 0.5,angle = 60), plot.caption=element_text(hjust=0))
if(isTRUE(getOption('knitr.in.progress'))==T){ } else {ggsave(paste0(i,".png"),dpi=320)}
## NULL
casos_no_cubiertos<- CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=macrozona)%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt<2009) %>% dplyr::ungroup()%>% summarise(sum_total=sum(n_2_grupos))%>% unlist() CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=macrozona)%>% dplyr::group_by(fech_ing_qrt, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::filter(fech_ing_qrt>=2009) %>% ggplot2::ggplot(aes(x = fech_ing_qrt, y = freq,fill=grupo_var))+ geom_area(alpha=0.6 , size=.5, colour="white") + scale_fill_viridis(discrete = T) + sjPlot::theme_sjplot2() + scale_x_yearqtr(format="%YQ%q", n=18, limits=c(zoo::as.yearqtr("2009-04-01"), max=zoo::as.yearqtr("2019-11-13")))+ labs(x="",y="Porcentajes", caption= paste0("Nota. Se ignoraron ", casos_no_cubiertos, "casos con una fecha de admisión anterior al año 2009;\n", "Norte= Arica, Tarapacá, Antofagasta, Atacama y Coquimbo;\n", "Centro= Valparaíso, Metropolitana, O'Higgins, Maule, Ñuble y Bío-bío;\n", "Sur= La Araucanía, Los Ríos, Los Lagos, Aysén y Magallanes;\n", "https://www.cepchile.cl/cep/site/docs/20191120/20191120163604/libro_inmigracion_cifras.pdf"))+ #ylim(0,101)+ scale_y_continuous(limits=c(0,1),labels = scales::percent) + theme(legend.position="bottom")+ guides(fill=guide_legend(ncol=4))+ theme(legend.text = element_text(size=9))+ theme(legend.title = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), panel.grid.major.x = element_blank(), panel.background = element_blank(), axis.title.x = element_blank())+ theme(axis.text.x = element_text(vjust = 0.5,hjust = 0.5,angle = 60), plot.caption=element_text(size=8.5,hjust=0))
if(isTRUE(getOption('knitr.in.progress'))==T){ } else {ggsave(paste0("macrozona",".png"),dpi=320)}
## NULL
datos_region <- chilemapas::generar_regiones(mapa = chilemapas::mapa_comunas) pop_region<- chilemapas::censo_2017_comunas%>% dplyr::group_by(codigo_comuna)%>% summarise(sum_pop=sum(poblacion))%>% dplyr::left_join( chilemapas::mapa_comunas, by="codigo_comuna")%>% dplyr::group_by(codigo_region)%>% summarise(n=sum(sum_pop)) casos_region<-CONS_C1_df_dup_JUL_2020 %>% group_by(nombre_region)%>% summarise(n=n())%>% dplyr::mutate(cod.V1= str_sub(nombre_region, -3, -2)) dat2<-datos_region %>% dplyr:::left_join(as_tibble(casos_region), by=c("codigo_region"="cod.V1")) %>% dplyr::left_join(as_tibble(pop_region), c("codigo_region"="codigo_region"))%>% dplyr::rename("pop"="n.y","n"="n.x")%>% dplyr::mutate(pop_rate=round((n/pop)*100000),0)%>% dplyr::mutate(tooltip=paste0(`nombre_region`,"=",`n`,",\n Tasa:",pop_rate)) gg2<-ggplot(data=dat2) + #geom_sf(aes(fill=as.numeric(dat2$value))) + theme_minimal() + geom_sf_interactive(aes(fill = cut(as.numeric(`pop_rate`),round(quantile(as.numeric(`pop_rate`),na.rm=T),0), include.lowest=TRUE,dig.lab=10,right=T), tooltip = tooltip, data_id = codigo_region))+ #scale_fill_brewer(palette="RdYlGn",direction = -1,na.value="grey80") + scale_fill_viridis_d(direction = 1,option= "E")+ #scale_fill_gradient(low="white",high="steelblue") + #scale_fill_viridis(direction = 1, option="E")+ labs(caption='Note: Sin casos registrados, en blanco',fill="N° tratamientos\npor cada 100,000 hab\n(cuartiles)")+ theme(legend.title=element_text(size=20), legend.text=element_text(size=18), plot.caption = element_text(hjust = 0, face = "italic",size=18)) gg2
ggsave(paste0("mapa_chile",".png"),dpi=500)
mapa_comunas = chilemapas::mapa_comunas pop_comuna<- chilemapas::censo_2017_comunas%>% dplyr::group_by(codigo_comuna)%>% summarise(sum_pop=sum(poblacion)) codigo_comunas<- CONS_C1_df_dup_JUL_2020 %>% dplyr::filter(grepl("Metropolitana",nombre_region))%>% dplyr::group_by(comuna_residencia_cod)%>% summarise(n=n())%>% dplyr::mutate(cod.V1= str_sub(comuna_residencia_cod, -6, -2))%>% # dplyr::select(-comuna_residencia_cod)%>% dplyr::mutate(cod.V1= stringr::str_replace(cod.V1, "\\(", "0")) dat2<-mapa_comunas %>% dplyr:::left_join(as_tibble(codigo_comunas), by=c("codigo_comuna"="cod.V1")) %>% dplyr::filter(codigo_region=="13")%>% dplyr::left_join(as_tibble(pop_comuna), c("codigo_comuna"="codigo_comuna"))%>% dplyr::mutate(pop_rate=(n/sum_pop)*100000)%>% dplyr::mutate(tooltip=paste0(`comuna_residencia_cod`,"=",`n`,",\n Tasa:",round(pop_rate,0)))%>% dplyr::mutate(n_cut=cut(as.numeric(pop_rate),round(quantile(as.numeric(pop_rate),na.rm=T),0), include.lowest=TRUE,dig.lab=10,right=T)) dat2 <- as_tibble(dat2) gg23<- ggplot(data=dat2) + # geom_sf(aes(fill=factor(n),geometry=geometry)) + theme_minimal() + geom_sf_interactive(aes(fill = pop_rate, tooltip = tooltip, data_id = codigo_comuna, geometry= geometry))+ geom_sf_interactive(aes(fill = pop_rate, tooltip = tooltip, data_id = codigo_comuna, geometry= geometry))+ scale_fill_viridis(direction = 1, option="E")+ #scale_colour_brewer(breaks = rev(levels(dsamp$clarity)))+ labs(caption='Fuente: CENSO 2017',fill="N° tratamientos\npor cada 100,000 hab (cuartiles)")# geom_sf(data = dat2, aes(fill = value)) + # coord_sf( expand = T) gg23
if(isTRUE(getOption('knitr.in.progress'))==T){ } else {ggsave(paste0("comunas_rm",".png"),dpi=320)}
## NULL
df_plots<- data.frame(cbind( variables=c("edad_al_ing","dias_trat_imp","edad_ini_cons", "edad_ini_sus_prin"), colors=c("grey70","mediumpurple2","khaki3","cornflowerblue") )) casos_no_cubiertos<- CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=as.numeric(get(df_plots[1,"variables"])))%>% dplyr::group_by(fech_ing_qrt)%>% summarise(median=quantile(grupo_var,.5,na.rm=T), q25=quantile(grupo_var,.25,na.rm=T), q75=quantile(grupo_var,.75,na.rm=T), n=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::filter(fech_ing_qrt<2009) %>% dplyr::ungroup() #eval(parse(text=df_plots[i,"variables"]))<- edad_al_ing<- CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=as.numeric(get(df_plots[1,"variables"])))%>% dplyr::group_by(fech_ing_qrt)%>% summarise(median=quantile(grupo_var,.5,na.rm=T), q25=quantile(grupo_var,.25,na.rm=T), q75=quantile(grupo_var,.75,na.rm=T), n=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::filter(fech_ing_qrt>=2009) %>% ggplot2::ggplot(aes(x = fech_ing_qrt))+ geom_ribbon(aes(ymin = q25, ymax = q75), fill = df_plots[1,"colors"]) + geom_line(aes(y = median))+ sjPlot::theme_sjplot2() + scale_x_yearqtr(format="%YQ%q", n=18, limits=c(zoo::as.yearqtr("2009-04-01"), max=zoo::as.yearqtr("2019-11-13")))+ labs(x="",y="Valores", caption= paste0("Nota. Se ignoraron ",sum(casos_no_cubiertos$n), " casos con una fecha de admisión anterior al año 2009;\n", "Valores por año y trimestre"))+ #ylim(5,30)+ #scale_y_continuous(limits=c(0,1),labels = scales::percent) + theme(legend.position="bottom")+ guides(fill=guide_legend(ncol=3))+ theme(legend.text = element_text(size=10))+ theme(legend.title = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), panel.grid.major.x = element_blank(), panel.background = element_blank(), axis.title.x = element_blank())+ theme(axis.text.x = element_text(vjust = 0.5,hjust = 0.5,angle = 60), plot.caption=element_text(hjust=0)) edad_al_ing
if(isTRUE(getOption('knitr.in.progress'))==T){ } else {ggsave(paste0(df_plots[1,"variables"],".png"),dpi=320)}
## NULL
df_plots<- data.frame(cbind( variables=c("edad_al_ing","dias_treat_imp_sin_na","edad_ini_cons", "edad_ini_sus_prin"), colors=c("grey70","mediumpurple2","khaki3","cornflowerblue") )) casos_no_cubiertos<- CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=as.numeric(get(df_plots[2,"variables"])))%>% dplyr::group_by(fech_ing_qrt)%>% summarise(median=quantile(grupo_var,.5,na.rm=T), q25=quantile(grupo_var,.25,na.rm=T), q75=quantile(grupo_var,.75,na.rm=T), n=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::filter(fech_ing_qrt<2009) %>% dplyr::ungroup() #eval(parse(text=df_plots[i,"variables"]))<- dias_trat_imp<- CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=as.numeric(get(df_plots[2,"variables"])))%>% dplyr::group_by(fech_ing_qrt)%>% summarise(median=quantile(grupo_var,.5,na.rm=T), q25=quantile(grupo_var,.25,na.rm=T), q75=quantile(grupo_var,.75,na.rm=T), n=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::filter(fech_ing_qrt>=2009) %>% ggplot2::ggplot(aes(x = fech_ing_qrt))+ geom_ribbon(aes(ymin = q25, ymax = q75), fill = df_plots[2,"colors"]) + geom_line(aes(y = median))+ sjPlot::theme_sjplot2() + scale_x_yearqtr(format="%YQ%q", n=18, limits=c(zoo::as.yearqtr("2009-04-01"), max=zoo::as.yearqtr("2019-11-13")))+ labs(x="",y="Valores", caption= paste0("Nota. Se ignoraron ",sum(casos_no_cubiertos$n), " casos con una fecha de admisión anterior al año 2009;\n", "Valores por año y trimestre"))+ #ylim(5,30)+ #scale_y_continuous(limits=c(0,1),labels = scales::percent) + theme(legend.position="bottom")+ guides(fill=guide_legend(ncol=3))+ theme(legend.text = element_text(size=10))+ theme(legend.title = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), panel.grid.major.x = element_blank(), panel.background = element_blank(), axis.title.x = element_blank())+ theme(axis.text.x = element_text(vjust = 0.5,hjust = 0.5,angle = 60), plot.caption=element_text(hjust=0)) dias_trat_imp
if(isTRUE(getOption('knitr.in.progress'))==T){ } else {ggsave(paste0(df_plots[2,"variables"],".png"),dpi=320)}
## NULL
df_plots<- data.frame(cbind( variables=c("edad_al_ing","dias_trat_imp","edad_ini_cons", "edad_ini_sus_prin"), colors=c("grey70","mediumpurple2","khaki3","cornflowerblue") )) casos_no_cubiertos<- CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=as.numeric(get(df_plots[3,"variables"])))%>% dplyr::group_by(fech_ing_qrt)%>% summarise(median=quantile(grupo_var,.5,na.rm=T), q25=quantile(grupo_var,.25,na.rm=T), q75=quantile(grupo_var,.75,na.rm=T), n=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::filter(fech_ing_qrt<2009) %>% dplyr::ungroup() #eval(parse(text=df_plots[i,"variables"]))<- edad_ini_cons<- CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=as.numeric(get(df_plots[3,"variables"])))%>% dplyr::group_by(fech_ing_qrt)%>% summarise(median=quantile(grupo_var,.5,na.rm=T), q25=quantile(grupo_var,.25,na.rm=T), q75=quantile(grupo_var,.75,na.rm=T), n=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::filter(fech_ing_qrt>=2009) %>% ggplot2::ggplot(aes(x = fech_ing_qrt))+ geom_ribbon(aes(ymin = q25, ymax = q75), fill = df_plots[3,"colors"]) + geom_line(aes(y = median))+ sjPlot::theme_sjplot2() + scale_x_yearqtr(format="%YQ%q", n=18, limits=c(zoo::as.yearqtr("2009-04-01"), max=zoo::as.yearqtr("2019-11-13")))+ labs(x="",y="Valores", caption= paste0("Nota. Se ignoraron ",sum(casos_no_cubiertos$n), " casos con una fecha de admisión anterior al año 2009;\n", "Valores por año y trimestre"))+ ylim(5,30)+ #scale_y_continuous(limits=c(0,1),labels = scales::percent) + theme(legend.position="bottom")+ guides(fill=guide_legend(ncol=3))+ theme(legend.text = element_text(size=10))+ theme(legend.title = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), panel.grid.major.x = element_blank(), panel.background = element_blank(), axis.title.x = element_blank())+ theme(axis.text.x = element_text(vjust = 0.5,hjust = 0.5,angle = 60), plot.caption=element_text(hjust=0)) edad_ini_cons if(isTRUE(getOption('knitr.in.progress'))==T){ } else {ggsave(paste0(df_plots[3,"variables"],".png"),dpi=320)}
df_plots<- data.frame(cbind( variables=c("edad_al_ing","dias_trat_imp","edad_ini_cons", "edad_ini_sus_prin"), colors=c("grey70","mediumpurple2","khaki3","cornflowerblue") )) casos_no_cubiertos<- CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=as.numeric(get(df_plots[4,"variables"])))%>% dplyr::group_by(fech_ing_qrt)%>% summarise(median=quantile(grupo_var,.5,na.rm=T), q25=quantile(grupo_var,.25,na.rm=T), q75=quantile(grupo_var,.75,na.rm=T), n=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::filter(fech_ing_qrt<2009) %>% dplyr::ungroup() #eval(parse(text=df_plots[i,"variables"]))<- edad_al_ing<- CONS_C1_df_dup_JUL_2020 %>% dplyr::mutate(fech_ing_qrt=zoo::as.yearqtr(fech_ing)) %>% dplyr::mutate(grupo_var=as.numeric(get(df_plots[4,"variables"])))%>% dplyr::group_by(fech_ing_qrt)%>% summarise(median=quantile(grupo_var,.5,na.rm=T), q25=quantile(grupo_var,.25,na.rm=T), q75=quantile(grupo_var,.75,na.rm=T), n=n())%>% dplyr::ungroup()%>% dplyr::group_by(fech_ing_qrt)%>% dplyr::filter(fech_ing_qrt>=2009) %>% ggplot2::ggplot(aes(x = fech_ing_qrt))+ geom_ribbon(aes(ymin = q25, ymax = q75), fill = df_plots[4,"colors"]) + geom_line(aes(y = median))+ sjPlot::theme_sjplot2() + scale_x_yearqtr(format="%YQ%q", n=18, limits=c(zoo::as.yearqtr("2009-04-01"), max=zoo::as.yearqtr("2019-11-13")))+ labs(x="",y="Valores", caption= paste0("Nota. Se ignoraron ",sum(casos_no_cubiertos$n), " tratamientos con una fecha de admisión anterior al año 2009;\n", "Valores por año y trimestre"))+ ylim(5,30)+ #scale_y_continuous(limits=c(0,1),labels = scales::percent) + theme(legend.position="bottom")+ guides(fill=guide_legend(ncol=3))+ theme(legend.text = element_text(size=10))+ theme(legend.title = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), panel.grid.major.x = element_blank(), panel.background = element_blank(), axis.title.x = element_blank())+ theme(axis.text.x = element_text(vjust = 0.5,hjust = 0.5,angle = 60), plot.caption=element_text(hjust=0)) edad_al_ing if(isTRUE(getOption('knitr.in.progress'))==T){ } else {ggsave(paste0(df_plots[4,"variables"],".png"),dpi=320)}
24.708 (22.5%) corresponden a tratamientos con entradas posteriores para el mismo usuario.
17.764 usuarios presentan más de un tratamiento.
ggplot(CONS_C1_df_dup_JUL_2020,aes(x=diff_bet_treat),fill="steelblue")+ geom_histogram(bins=90)+ #theme_void() sjPlot::theme_sjplot2() + labs(y="Frecuencia",x= "Dif. con el siguiente Tratamiento (en días)", caption=paste0("Nota. Linea vertical= Mediana (",median(CONS_C1_df_dup_JUL_2020$diff_bet_treat,na.rm=T)," días de diferencia [IQR ",quantile(CONS_C1_df_dup_JUL_2020$diff_bet_treat,.25,na.rm=T),"-",quantile(CONS_C1_df_dup_JUL_2020$diff_bet_treat,.75,na.rm=T),"])"))+ geom_vline(xintercept = median(CONS_C1_df_dup_JUL_2020$diff_bet_treat,na.rm=T), color="darkred", size=1.5)+ theme(legend.title = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), panel.grid.major.x = element_blank(), panel.background = element_blank(), plot.caption=element_text(hjust=0))
if(isTRUE(getOption('knitr.in.progress'))==T){ } else {ggsave(paste0("Histograma_dias_entre_trat",".png"),dpi=320)}
## NULL
fill <- c("#5F9EA0", "#E1B378") data_diff_treat<- CONS_C1_df_dup_JUL_2020%>% #dplyr::mutate(motivodeegreso_mod_imp=ifelse(grepl("Abandono Tardio",motivodeegreso_mod_imp) & dias_treat_imp_sin_na<90,"Abandono Temprano",as.character(motivodeegreso_mod_imp)))%>% #dplyr::filter(!is.na(diff_bet_treat))%>% dplyr::mutate(dias_trat_imp=round(dias_treat_imp_sin_na,0)) %>% dplyr::mutate(dias_trat_imp=cut2(dias_trat_imp, g =30))%>% dplyr::mutate(grupo_var=motivodeegreso_mod_imp)%>% dplyr::group_by(dias_trat_imp, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(dias_trat_imp)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::ungroup() mot_egres_por_dias_trat<- ggplot2::ggplot(data_diff_treat, aes(x = dias_trat_imp, y = freq,fill=grupo_var))+ geom_bar(stat='identity', alpha=.8) + scale_x_discrete()+ scale_fill_viridis(discrete = T) + sjPlot::theme_sjplot2()+ labs(x="",y="Porcentajes", caption= paste0("Nota. Se dividieron los Días de Tratamiento en 30 partes iguales;\n", "Porcentajes por días de tratamiento"))+ #ylim(0,101)+ scale_y_continuous(limits=c(0,1),labels = scales::percent) + theme(legend.position="bottom")+ guides(fill=guide_legend(ncol=3))+ theme(legend.text = element_text(size=10))+ theme(legend.title = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), panel.grid.major.x = element_blank(), panel.background = element_blank(), axis.title.x = element_blank())+ theme(axis.text.x = element_text(vjust = 0.5,hjust = 0.5,angle = 60), plot.caption=element_text(hjust=0)) if(isTRUE(getOption('knitr.in.progress'))==T){ ggplotly(mot_egres_por_dias_trat) } else {ggsave(paste0("motivo de egreso por días trat",".png"),dpi=320)}
data_diff_treat<- CONS_C1_df_dup_JUL_2020%>% dplyr::filter(!is.na(diff_bet_treat))%>% janitor::tabyl(motivodeegreso_mod_imp)%>% adorn_pct_formatting()%>% dplyr::filter(motivodeegreso_mod_imp %in% c("Abandono Tardio","Abandono Temprano","Alta Administrativa","Alta Terapéutica","Derivación"))%>% #dplyr::mutate(motivodeegreso_mod_imp=recode(motivodeegreso_mod_imp,"Abandono Tardio"=".Abandono Tardio", # "Abandono Temprano" = ".Abandono Temprano"))%>% #el primer, el a cambiar y el otro es el original arrange(motivodeegreso_mod_imp) p<- plotly::plot_ly(data_diff_treat, sort = FALSE,labels = ~motivodeegreso_mod_imp, values = ~n, type = 'pie',hole = 0.3,textposition = 'outside',textinfo = 'label+percent', marker = list(colors = c("hotpink4","cornsilk","lightgrey","darkgoldenrod","mediumpurple"))) %>% #direction = "clockwise", layout(xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE), yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))%>% layout(legend = 'none') if(isTRUE(getOption('knitr.in.progress'))==T){ p } else {plotly_IMAGE(p, width = 1500, height = 500, format = "png", scale = 2,dpi=700, out_file = "G:/Mi unidad/Alvacast/SISTRAT 2019 (github)/Presentación a SENDA Jun 2020/motivo de egreso en tratamientos que tienen readmisiones.png")}
fill <- c("#5F9EA0", "#E1B378") data_diff_treat<- CONS_C1_df_dup_JUL_2020%>% dplyr::filter(!is.na(diff_bet_treat))%>% dplyr::mutate(diff_bet_treat=round(diff_bet_treat,0)) %>% dplyr::mutate(diff_bet_treat_g=cut2(diff_bet_treat, g =30))%>% dplyr::mutate(grupo_var=motivodeegreso_mod_imp)%>% dplyr::group_by(diff_bet_treat_g, grupo_var)%>% summarise(n_2_grupos=n())%>% dplyr::ungroup()%>% dplyr::group_by(diff_bet_treat_g)%>% dplyr::mutate(freq = (n_2_grupos / sum(n_2_grupos)))%>% dplyr::ungroup() mot_egres_por_dias_diff_entre_trat<- ggplot2::ggplot(data_diff_treat, aes(x = diff_bet_treat_g, y = freq,fill=grupo_var))+ geom_bar(stat='identity', alpha=.8) + scale_x_discrete()+ scale_fill_viridis(discrete = T) + sjPlot::theme_sjplot2()+ labs(x="",y="Porcentajes", caption= paste0("Nota. Se dividieron las Diferencias entre tratamientos en 30 partes iguales;\n", "Porcentajes por días de tratamiento;\n", "Se descartan aquellos registros que no poseen un tratamiento posterior"))+ #ylim(0,101)+ scale_y_continuous(limits=c(0,1),labels = scales::percent) + theme(legend.position="bottom")+ guides(fill=guide_legend(ncol=3))+ theme(legend.text = element_text(size=10))+ theme(legend.title = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), panel.grid.major.x = element_blank(), panel.background = element_blank(), axis.title.x = element_blank())+ theme(axis.text.x = element_text(vjust = 0.5,hjust = 0.5,angle = 60), plot.caption=element_text(hjust=0)) if(isTRUE(getOption('knitr.in.progress'))==T){ ggplotly(mot_egres_por_dias_diff_entre_trat) } else { ggsave(paste0("motivo de egreso por días diff entre trat",".png"),dpi=320) }