-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.Rmd
1517 lines (1011 loc) · 62.4 KB
/
index.Rmd
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "CARACTERIZACIÓN DE LA POBLACIÓN PENITENCIARIA EN EL PERÚ"
date: "Diciembre 2023"
output:
html_document:
code_folding: show
toc: yes
toc_depth: 5
toc_float: yes
theme: readable
lang: es-ES
df_print: paged
editor_options:
markdown:
wrap: 72
---
------------------------------------------------------------------------
```{css echo = FALSE}
# Cambiar color del título y subtítulos
.columns {display:flex;}
h1 {color: #052A59;}
h2 {color: #274873;}
h3 {color: #000000;}
h4 {color: #000000;}
```
```{css echo = FALSE}
.list-group-item.active, .list-group-item.active:focus, .list-group-item.active:hover {
z-index: 2;
color: #FFFFFF;
background-color: #052A59;
border-color: #274873;
}
```
```{r, echo=FALSE}
# Agregar logo
htmltools::img(src = knitr::image_uri("logo.png"),
style = 'position: absolute;
top:3;
right:0;
padding:10px;',
width = "250px",
heigth = "250px")
```
## Información general
**Estudiantes:**
- Aburto Camacllanqui, Elías
- Avilés Elias, Gabriel
- Huaman Loayza, Guido
- Ramírez De la Cruz, Guadalupe
- Rivas Su, Juan Diego
**Curso:** Fundamento de R para CCSS y Gestión Pública 2023
**Diplomatura:** Especialización en Ciencia de Datos para las Ciencia Sociales y la Gestión Pública
## 1. Introducción
### Contexto
La teoría de la tensión sostiene que la criminalidad surge de la frustración que experimentan las personas cuando no pueden lograr los fines culturales que la sociedad les impone, debido a la falta de medios institucionales legítimos para hacerlo (Merton, 1938). Así, las personas que se ven imposibilitadas de alcanzar el "objetivo de riqueza" que la sociedad valora, recurren a medios ilícitos para obtenerlo (1938, p. 679), lo que implica que la estructura social influye en la elección de las personas de cometer delitos. (Featherstone, 2003) y que la desigualdad de oportunidades incide en la exclusión de las personas de la sociedad y se convierte en un factor que propicia el crimen (Cheong & Wu, 2015, p. 203).
En tal sentido, el Pacto Internacional de Derechos Civiles y Políticos y la Convención Americana de Derechos Humanos señalan que la finalidad esencial de las penas es la reforma y readaptación social de las personas dentro del centro penitenciario (Orosco, 2017). Siendo ello así, el periodo de reclusión debe ser utilizado para asegurar el retorno a la comunidad (Oficina de las Naciones Unidas contra la Droga y el Delito, 2013); es decir, la recuperación o reinserción social, una vez habiendo logrado reeducarse y rehabilitarse (Magán, 2017).
Diversos autores señalan que el hacinamiento en el establecimiento penitenciario afecta en la eficiencia de la búsqueda de la reinserción social de los internos (Oficina de las Naciones Unidas contra la Droga y el Delito, 2013 & Orosco, 2017). Esto se debe a que en dicho entorno se encuentran expuestos a una serie de riesgos, como el abuso de sustancias ilegales y los altercados por disputas del espacio (Peñaloza, 2017); asimismo, ocasiona problemas psicológicos y emocionales ante la ausencia de espacios privados (Defensoría del Pueblo, 2018) y también se ve reducida la cantidad de espacios destinados al trabajo en talleres y actividades educativas (Magán, 2017).
Según el Censo Nacional de Población Penitenciaria 2016, desarrollado por el Instituto Nacional de Estadística e Informática – INEI y el Instituto Nacional Penitenciario – INPE, los centros penitenciarios del Perú se encuentran operando alrededor del 120% de su capacidad (Defensoría del Pueblo, 2018 & Peñaloza, 2017). Es por ello que, diversos autores cuestionan la capacidad de los Centros Penitencias en el Perú para albergar la cantidad de internos e internas que alojan, las condiciones de vida que existen dentro, así como de su funcionamiento como espacios de recuperación social de los reclusos.
En el año 2016, el Instituto Nacional de Estadística e Informática – INEI y el Instituto Nacional Penitenciario – INPE, desarrollaron el Censo Nacional de Población Penitenciaria, con el objetivo de obtener información estadística sobre la población penitenciaria adulta, que sirva para elaborar políticas públicas de prevención del delito orientadas a la reeducación, rehabilitación y reincorporación del interno a la sociedad. Sin embargo, cabe indicar que el presente año se discute en el Congreso de la República la generación de condiciones para la realización de un nuevo Censo Nacional de Población Penitenciaria en el año 2024; dado que ven por conveniente contar con información actualizada.
### Problema
La reintegración a la sociedad de los internos se ve afectada por una serie de desafíos sociales, económicos y personales; tales como la familia, los compañeros, el abuso de sustancias o adicción, el nivel de educación o destreza, la marginación social, el abuso físico o emocional, el padecer de alguna discapacidad física, mental o problema de salud, el haber tenido un estilo de vida delictivo que inició a temprana edad (Oficina de las Naciones Unidas contra la Droga y el Delito, 2013). Es así que el interno puede verse envuelto en un ciclo de reincidencia delictiva ante la imposibilidad de reinsertarse en la sociedad. Al respecto, Hernández (2018) identifica dos tipos de factores de riesgo de reincidencia delictiva: i) factores imposibles de cambiar (historia delictiva, estructura familiar o conductas antisociales ocurridas a temprana edad) y ii) los maleables (malas influencias, consumo de sustancias, etc).
Es por ello que, en un contexto de posible reincidencia delictiva, los cambios en las circunstancias familiares y de trabajo son factores claves para el desistimiento de cometer delitos (Oficina de las Naciones Unidas contra la Droga y el Delito, 2013). Un análisis realizado por Peñaloza (2017) sobre los factores asociados a las trayectorias exitosas de reinserción social identifica que el uso edificante del tiempo durante la fase de confinamiento, y un capital social que provea soporte emocional y opere como mecanismo de control social, permite superar las barreras al mercado laboral y asegurar la satisfacción de necesidades básicas.
### Objetivo
> > En ese contexto, el presente trabajo persigue el objetivo de describir las principales características relacionadas a las condiciones sociodemográficas previas en las que el interno vivía cuando cometía crímenes, las condiciones en las que conviven los internos de los Centros Penitenciarios en el Perú y las expectativas del interno al salir del Centro Penitenciario, a partir de la revisión al Censo Nacional de Población Penitenciaria 2016, realizado por el INEI e INPE.
Para dicho fin se han optado por observar las variables asociadas a los siguientes aspectos en tres etapas de la vida del interno(a):
- Antecedentes y aspectos sociodemográficos previos al encarcelamiento
- Condiciones sociales y familiares del interno(a)
- Información sobre el contexto delictivo del interno(a)
- Durante el encarcelamiento
- Información general del Centro Penitenciario
- Información general del interno(a)
- Contexto del delito
- Condiciones de vida y convivencia del interno(a) dentro del Centro Penitenciario
- Después del encarcelamiento
- Expectativas al salir del Centro Penitenciario
## 2. Metodología
### Base de datos
El estudio busca realizar un análisis descriptivo de la población penitenciaria en Perú con datos registrado en el censo del año 2016 obtenidos a partir de los microdatos del INEI. Para ello, se seleccionaron un grupo de variables que busca proporcionar una visión amplia de las características de la población en tres momentos cruciales: antes, durante y después de su reclusión. Para ello, se utilizaron los datos del censo penitenciario del año 2016, como se mencionó. El objetivo de este es recopilar información estadística de la población penitenciaria de personas adultas. Este censo se ejecutó en 66 establecimientos penitenciarios a nivel nacional, abarcando aproximadamente 77,500 internos. La cobertura geográfica incluye 24 departamentos del país y la Provincia Constitucional del Callao.
El censo se divide en varios capítulos:
- Capítulo 100: Condiciones Sociales y familiares del Interno
- Capítulo 200: Tipificación del Delito
- Capítulo 300: Condiciones de Vida en el Establecimiento Penitenciario
- Capítulo 400: Rol de las Instituciones.
Estos capítulos abordan aspectos específicos de la población penitenciaria, desde condiciones sociales y familiares hasta la tipificación del delito, condiciones de vida en el establecimiento penitenciario y el papel de las instituciones en el proceso de rehabilitación.
Estos capítulos abordan aspectos específicos de la población penitenciaria, desde condiciones sociales y familiares hasta la tipificación del delito, condiciones de vida en el establecimiento penitenciario y el papel de las instituciones en el proceso de rehabilitación.
**Antes de la reclusión:**
- Se revisan datos relacionados con la vida previa al ingreso al establecimiento penitenciario, considerando el nivel de estudios alcanzado, las razones para no continuar con la educación, la presencia de enfermedades, el consumo de sustancias, el historial laboral y la posible influencia del entorno familiar en la predisposición al delito.
**Durante la reclusión:**
- Se utilizan los datos que describen la vida dentro del establecimiento penitenciario, abordando cuestiones como el delito genérico cometido, el idioma materno, la participación en programas educativos y laborales, así como las actividades realizadas durante el último mes. También se explora la frecuencia de visitas familiares y las razones detrás de la no participación en actividades institucionales.
**Después de la reclusión:**
- Por último, se utilizan los datos acerca de las aspiraciones y planes de los internos una vez liberados. Esta sección busca comprender sus perspectivas a futuro.
### Preprocesamiento
Se integraron las bases de cada capítulo en un solo dataframe.
```{r, warning=FALSE, out.width = "100%", message=FALSE}
library(tidyverse) #conjunto de paquetes
library("labelled") #Paquete para ver las etiquetas de las variables
#
#
# #Creando las bases de datos
# df1 <- haven::read_sav("01. Data/CARATULA/01_PENALES_CARATULA.sav")
# df2 <- haven::read_sav("01. Data/CONDICIONES DE VIDA DEL INTERNO/01_PENALES_CAP300.sav")
# df3 <- haven::read_sav("01. Data/CONDICIONES DEL INTERNO/01_PENALES_CAP100.sav")
# df4 <- haven::read_sav("01. Data/ROL DE LAS INSTITUCIONES/01_PENALES_CAP400.sav")
# df5 <- haven::read_sav("01. Data/TIPIFICACION DEL DELITO/01_PENALES_CAP200.sav")
#
# #Integrando las bases de datos
#
# df_1_2 <- inner_join(df1, df2, by = "ID_CARATULA", "INTERNO_ID")
# df_1_2_3 <- inner_join(df_1_2, df3, by = "ID_CARATULA", "INTERNO_ID")
# df_1_2_3_4 <- inner_join(df_1_2_3, df4, by = "ID_CARATULA", "INTERNO_ID")
# df_total <- inner_join(df_1_2_3_4, df5, by = "ID_CARATULA", "INTERNO_ID")
```
Se seleccionaron las variables de interés y se exportó en formato sav.
```{r, warning=FALSE, out.width = "100%", message=FALSE}
# Seleccionar las variables de Interés
# CNPP_data <- df_total |>
# select(EST_PENIT, GENERO, E_CIVIL, TSALUD_8,
# EDAD, NACIONALIDAD, NAC_DD, DELITO_GENERICO, DELITO_ESPECIFICO, P101, P104_1,
# P105, P107_1, P107C_1, P107_2, P107_3, P107_4, P107_5,
# P107_6, P107_7, P107_8, P107_9, P107_10, P107_11, P107_12,
# P109_1, P109_2, P109_3, P114, P133, P135, P201_DD, P204, P215, P220,
# P303, P306, P308, P313_1, P313_2, P313_3, P313_4, P313_5,
# P314, P315, P403_1, P403_2, P403_3, P403_4, P403_5, P403_6,
# P403_7)
# Guardar el dataframe en formato sav
# library(haven)
#
# write_sav(CNPP_data, "CNPP_data.sav")
```
Se observan las variables de interés y la identificación de posibles valores atípicos.
```{r, warning=FALSE, out.width = "100%", message=FALSE}
# Importar datos
CNPP_data <- haven::read_sav("CNPP_data.sav")
CNPP_data
# Presentar el contenido de las variables de interés
var_label(CNPP_data)
# Identificación de valores atípicos y datos perdidos
summary(CNPP_data)
```
### Análisis de Datos
En el marco de la presente investigación, se emplearon varios paquetes para facilitar la manipulación, limpieza y procesamiento de los datos. Inicialmente, se hizo uso del conjunto de paquetes "tidyverse", que incorpora herramientas como "dplyr" para transformar datos, "tidyr" para reorganizarlos y "ggplot2" para su visualización efectiva. El paquete "labelled" desempeñó el papel para la manipulación de datos etiquetados, permitiendo asignar, recuperar y gestionar etiquetas en las variables.
Con el propósito de gestionar el formato específico de los datos de la Población Penitenciaria, originalmente en SPSS (.sav), se implementó el paquete "haven" para la importación y exportación eficiente de datos. Además, "plotly" se utilizó para la creación de gráficos interactivos, mientras que "mapsPERU" facilitó la representación cartográfica con datos específicos de Perú, posibilitando la elaboración de mapas temáticos.
La mejora de la legibilidad en los gráficos fue abordada mediante el uso de "ggrepel", evitando superposiciones de etiquetas. En el ámbito de mapas interactivos, los paquetes "leaflet" y "leaflet.extras" posibilitaron la interacción con capas, marcadores y controles, mientras que "rworldxtra" proporcionó datos geográficos detallados a nivel mundial.
Adicionalmente, se integraron los paquetes "raster" y "sf" para manipular imágenes y realizar análisis espaciales en R. Este enfoque multidisciplinario con diversos paquetes contribuyó para realizar un análisis completo de los datos recopilados en el censo del año 2016.
## 3. Resultados
#### Antes: Antecedentes y aspectos sociodemográficos
##### GENERO
**Población Penitenciaria segun departamento y género**
```{r, warning=FALSE, out.width = "100%", message=FALSE}
df1 <- CNPP_data |>
group_by(NAC_DD,GENERO)|>
summarise(cantidad=n())|>
mutate(GENERO=case_when(GENERO==1~"HOMBRE",
TRUE~"MUJER"))
print(df1)
```
Para una mejor visualizacion de la data, se modificó la columna género, 1 al valor de hombre y 2 al valor de mujer.
```{r}
ggplot(df1, aes(x = NAC_DD, y = cantidad, fill = GENERO)) +
geom_bar(stat = "identity", position = "dodge", width = 1) +
labs(x = "Provincia", y = "Cantidad", title = "Cantidad de personas por provincia y género")+
coord_cartesian(ylim = c(0, max(df1$cantidad) * 1.2)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
```
En este grafico de barras podemos apreciar que Lima es la ciudad de origen con más reos tanto hombres como mujeres; seguido por Huanuco, La Libertad y Piura.
##### NACIONALIDAD
**CANTIDAD DE PERSONAS DE DIFERENTES NACIONALIDADES, RESUMEN DE TODAS LAS NACIONALIDADES**
```{r, warning=FALSE, out.width = "100%", message=FALSE}
CNPP_data|>
select(NACIONALIDAD)|>
count(NACIONALIDAD)|>
rename("NRO_DE_REOS"=n)|>
arrange(desc(NRO_DE_REOS))
```
Tabla simple que muestra la cantidad de reos por nacionalidad, vemos que por debajo de la Peruana estan las nacionalidades, Colombiana,Español y Mexicano.
##### EDAD
**Distribución de las edades de los reos penitenciarios**
```{r, warning=FALSE, out.width = "100%", message=FALSE}
library(ggplot2)
CNPP_data|>
select(EDAD,GENERO,P104_1,NAC_DD)|>
rename("NIVEL_EDUCATIVO"=P104_1,"LUGAR_DE_NACIMIENTO"=NAC_DD)|>
count(EDAD)|>
rename("TOTAL_DE_PERSONAS"=n)|>
ggplot()+
aes(x = EDAD, y = TOTAL_DE_PERSONAS)+
geom_line() +
labs(x = "Edad", y = "Cantidad de reos", title = "Distribución de Edades") +
theme_minimal()
```
Tenemos un diagrama de lineas simple que en el pico es aprox los 28 años, llegando a los 3 mil reos con esa edad, seguidos por los 22 años y 32 años. Son las 3 edades que tienen la mayor cantidad de reos.
##### NAC_DD
**Lugar de Nacimiento - Departamento**
```{r, warning=FALSE, out.width = "100%", message=FALSE}
library(dplyr)
CNPP_data_NAC <- CNPP_data %>%
filter(!is.na(NAC_DD) & NAC_DD != "") #Filtrando para omitir blanco y nulos
tabla_departamentos <- table(CNPP_data_NAC$NAC_DD) #Se crea la tabla de frecunencia
df_frecuencias <- as.data.frame(tabla_departamentos)
colnames(df_frecuencias) <- c("Departamento", "Frecuencia")
df_DEP_NAC <- df_frecuencias %>%
arrange(desc(Frecuencia))
print(df_DEP_NAC)
```
La tabla muestra que las personas que tienden a ser recluidas en un centro penitenciario pertenecen al departamento de Lima. Seguido de La Libertad, luego continúa Huánuco con alrededor de 4 mil personas. Cabe resaltar que el departamento de Lima muestra alrededor de cuatro veces la población del siguiente departamento.
##### P_101
**IDIOMA ESPECÍFICO APRENDIDO EN SU NIÑEZ**
```{r, warning=FALSE, out.width = "100%", message=FALSE}
idioma_var <- unique(CNPP_data$P101)
print(idioma_var)
```
```{r, warning=FALSE, out.width = "100%", message=FALSE}
# Creando la vriable que muestre los datos del idioma
CNPP_data <- CNPP_data %>%
mutate(P101 = as.character(P101))
CNPP_data <- CNPP_data %>%
mutate(P101_label = case_when(
P101 == "1" ~ "Quechua",
P101 == "2" ~ "Aymara",
P101 == "3" ~ "Ashaninka",
P101 == "4" ~ "Awajún/Aguaruna",
P101 == "5" ~ "Shipibo-Konibo",
P101 == "6" ~ "Otra lengua nativa",
P101 == "7" ~ "Castellano",
P101 == "8" ~ "Inglés",
P101 == "9" ~ "Otra lengua extranjera",
P101 == "10" ~ "Es sordomudo/a o mudo/a",
TRUE ~ "Desconocido"
))
idioma_var1 <- unique(CNPP_data$P101_label)
print(idioma_var1)
```
```{r, warning=FALSE, out.width = "100%", message=FALSE}
#Se crea la tabla que muestra la frecuencia del primer idioma aprendido
IDIOMA_FIL <- CNPP_data %>%
filter(!is.na(P101_label))
IDIOMA <- table(IDIOMA_FIL$P101_label)
IDIOMA_df <- as.data.frame(IDIOMA)
colnames(IDIOMA_df) <- c("Valor", "Frecuencia")
IDIOMA_df <- IDIOMA_df %>%
arrange(desc(Frecuencia))
print(IDIOMA_df)
```
Se encuentra que el Castellano es el idioma más hablado, como era de esperarse. Son los idiomas Quecha y Aymara, el segundo y tercer idioma más hablado, respectivamente.
##### P104_1
**ÚLTIMO GRADO EDUCATIVO ALCANZADO ANTES DE SER RECLUIDO**
```{r, warning=FALSE, out.width = "100%", message=FALSE}
educ_var <- unique(CNPP_data$P104_1)
print(educ_var)
```
```{r, warning=FALSE, out.width = "100%", message=FALSE}
# Creando la vriable que muestre las categorías de la variable educación
CNPP_data <- CNPP_data %>%
mutate(P104_1 = as.character(P104_1))
CNPP_data <- CNPP_data %>%
mutate(P104_1_label = case_when(
P104_1 == "2" ~ "Educación inicial",
P104_1 == "3" ~ "Primaria incompleta",
P104_1 == "4" ~ "Primaria completa",
P104_1 == "5" ~ "Secundaria incompleta",
P104_1 == "6" ~ "Secundaria completa",
P104_1 == "7" ~ "Superior no universitaria incompleta",
P104_1 == "8" ~ "Superior no universitaria completa",
P104_1 == "9" ~ "Superior universitaria incompleta",
P104_1 == "10" ~ "Superior universitaria completa",
TRUE ~ NA_character_
))
educ_var1 <- unique(CNPP_data$P104_1_label)
print(educ_var1)
```
```{r}
EDUC <- CNPP_data %>%
filter(!is.na(P104_1_label))
# Crear un gráfico de barras para la variable P104_1_label
ggplot(EDUC, aes(x = P104_1_label)) +
geom_bar(aes(y = ..count..), fill = "pink", color = "black", stat = "count") +
geom_text(aes(label = ..count..), stat = "count", vjust = -0.5) +
labs(title = "Distribución de Niveles de Educación",
x = "Nivel de Educación",
y = "Frecuencia") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 20, hjust = 1))
```
* Se crea el gráfico que brinda mayor detalle acerca del nivel de educación. En este sentido, se encuentra que las categoría secundaria completa e incompleta son en las que mayormente se localizan los convictos.
##### P105
**MOTIVO POR EL CÚAL NO CULMINÓ SUS ESTUDIOS**
```{r, warning=FALSE, out.width = "100%", message=FALSE}
educ_105 <- unique(CNPP_data$P105)
print(educ_105)
```
```{r, warning=FALSE, out.width = "100%", message=FALSE}
# Creando la vriable que muestre las categorías de la variable educación
CNPP_data <- CNPP_data %>%
mutate(P105 = as.character(P105))
CNPP_data <- CNPP_data %>%
mutate(P105_label = case_when(
P104_1 == "1" ~ "La familia no le permitió",
P104_1 == "2" ~ "La familia es/era muy pobre",
P104_1 == "3" ~ "Tenía necesidad económica",
P104_1 == "4" ~ "No le gustaba estudiar",
P104_1 == "5" ~ "Lo expulsaron",
P104_1 == "6" ~ "Por haber ingresado a prisión",
P104_1 == "7" ~ " Tenía que cuidar a mis hermanos(as)",
P104_1 == "8" ~ "Mi pareja me lo impidió",
TRUE ~ NA_character_
))
razon_var1 <- unique(CNPP_data$P105_label)
print(razon_var1)
```
```{r}
RAZON <- CNPP_data %>%
filter(!is.na(P105_label))
# Crear un gráfico de barras para la variable P105_label
ggplot(RAZON, aes(x = P105_label)) +
geom_bar(aes(y = ..count..), fill = "lightgreen", color = "black", stat = "count") +
geom_text(aes(label = ..count..), stat = "count", vjust = -0.5) +
labs(title = "Distribución de Razones por las que dejó de estudiar",
x = "Razón por la que dejo de estudiar",
y = "Frecuencia") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 55, hjust = 1))
```
* Se encuentra que las razones principales por las que no culminaron sus estudios es porque los expulsaron, por haber ingresado a prisión y por necesidad económica.
##### P109
**¿ANTES DE INGRESAR AL E.P. USTED CONSUMÍA: Drogas? ¿ANTES DE INGRESAR AL E.P. USTED CONSUMÍA: Bebidas alcohólicas? ¿ANTES DE INGRESAR AL E.P. USTED CONSUMÍA: Cigarrillos?**
```{r, warning=FALSE, out.width = "100%", message=FALSE}
# Se crea una nueva variable, denominada "consumo"; cuyos valor es "Sí" cuando el reo consumía drogas, bebidas alcohólicas o cigarillos antes de ingresar al centro penitenciario.
CNPP_data <- CNPP_data |>
mutate(consumo = case_when(P109_1 == 1 & (P109_2 == 2 | P109_2 == 3) & (P109_3 == 2 | P109_3 == 3) ~ "DROGAS", (P109_1 == 2 | P109_1 == 3) & P109_2 == 1 & (P109_3 == 2 | P109_3 == 3) ~ "BEBIDAS ALCOHOLICAS", (P109_1 == 2 | P109_1 == 3) & (P109_2 == 2 | P109_2 == 3) & P109_3 == 1 ~ "CIGARRILLOS", P109_1 == 1 & P109_2 == 1 & (P109_3 == 2 | P109_3 == 3) ~ "DROGAS Y BEBIDAS ALCOHOLICAS", P109_1 == 1 & (P109_2 == 2 | P109_2 == 3) & P109_3 == 1 ~ "DROGAS Y CIGARRILLOS", (P109_1 == 2 | P109_1 == 3) & P109_2 == 1 & P109_3 == 1 ~ "BEBIDAS ALCOHOLICAS Y CIGARRILLOS", P109_1 == 1 & P109_2 == 1 & P109_3 == 1 ~ "DROGAS, BEBIDAS ALCOHOLICAS Y CIGARRILLOS", TRUE ~ "NO/NO CONTESTA"))
# Utilizando 'count' y 'mutate' hallamos la cantidad de reos que consumían drogas, bebidas alcohólicas o cigarillos antes de ingresar al centro penitenciario, así como el porcentaje que representan respecto del total.
CNPP_data |>
count(consumo) |>
mutate(Porcentaje_consumo = round(n/sum(n)*100,1)) |>
print(n = Inf) |>
arrange(desc(n))
# A partir de la variable obtenida ('consumo'), se presenta a continuación un gráfico de barras que permitirá observar la cantidad de reos que consumían drogas, bebidas alcohólicas o cigarillos antes de ingresar al centro penitenciario.
etiqueta_1 <- c(`1`="Sí",
`2`="No",
`3`="No sabe/No contesta")
CNPP_data|>
mutate(consumo = recode_factor(consumo,!!!etiqueta_1)) |>
count(consumo) |>
ggplot() +
aes(x=1, y=n, fill=consumo) +
geom_col(position = "dodge", width = 0.8) +
geom_text(aes(label = n),
position = position_dodge(width = 0.8), vjust = -0.5, size = 3, fontface = "bold") +
theme_minimal() +
scale_fill_brewer(palette="Set1") +
labs(
title = "PERÚ: CONSUMO ANTES DE INGRESAR AL ESTABLECIMIENTO \nPENITENCIARIO",
subtitle = "(Frecuencia, porcentaje)",
x = "Consumo",
y = "Frecuencia")+
theme(axis.text.x = element_blank())
```
Como puede observarse, un gran número de reos señala que consumían bebidas alcohólicas antes de ingresar al establecimiento penitenciario. En segundo lugar, 18,117 reos mencionan que no consumían ninguna de las opciones previamente mencionadas o prefirieron no contestar a la interrogante.
Luego de ello, podemos observar que lo siguen en cantidad los reos que consumían "Bebidas alcohólicas y cigarrillos", "Drogas, bebidas alcohólicas y cigarrilllos" y "Drogas y bebidas alcohólicas"; al respecto, puede observarse que las bebidas alcohólicas tienen una fuerte presencia en el consumo de los reos, desde antes de ingresar al establecimiento penitenciario.
##### P114
**ANTES DE INGRESAR AL ESTABLECIMIENTO PENITENCIARIO, ¿USTED TRABAJÓ ALGUNA VEZ?**
```{r, warning=FALSE, out.width = "100%", message=FALSE}
# Utilizando 'count' y 'mutate' hallamos la cantidad de reos que trabajaron alguna vez antes de ingresar al establecimiento penitenciario, así como el porcentaje que representan respecto del total.
CNPP_data |>
count(P114) |>
mutate(Porcentaje_trabajo_antes = round(n/sum(n)*100,1)) |>
print(n = Inf) |>
arrange(desc(n)) |>
rename("cantidad_reos"=n)
# A partir de ello, se presenta a continuación un gráfico circular que permitirá observar la cantidad de reos que trabajaron o no alguna vez antes de ingresar al establecimiento penitenciario.
table(CNPP_data$P114)
etiqueta_1 <- c(`1`="Sí",
`2`="No",
`3`="No sabe/No contesta")
CNPP_data |>
mutate(P114 = recode_factor(P114,!!!etiqueta_1)) |>
count(P114) |>
mutate(
Porcentaje = round(n/sum(n)*100,1)) |>
ggplot() +
aes(x=1, y=Porcentaje, fill=P114) +
geom_bar(stat="identity") +
geom_text(aes(label = paste0(n,", ",round(Porcentaje,1),"%")),
position = position_stack(vjust = 0.5), size=3, fontface = "bold") +
coord_polar(theta = "y") +
theme_void() +
scale_fill_brewer(palette="Set1") +
labs(
title = "PERÚ: POBLACIÓN PENITENCIARIA QUE TRABAJÓ ANTES \nINGRESAR AL ESTABLECIMIENTO PENITENCIARIO",
subtitle = "(Frecuencia, porcentaje)")
```
Como puede observarse, el 95.6% de los reos sí trabajó alguna vez antes de ingresar al establecimiento penitenciario.
##### P113
**¿ALGÚN MIEMBRO DE SU FAMILIA ESTUVO PRESO EN UN ESTABLECIMIENTO PENITENCIARIO ALGUNA VEZ?**
```{r, warning=FALSE, out.width = "100%", message=FALSE}
# Utilizando 'count' y 'mutate' hallamos la cantidad de reos que tuvieron a algún miembro de su familia preso en un establecimiento penitenciario, así como el porcentaje que representan respecto del total.
CNPP_data |>
count(P133) |>
mutate(Porcentaje_trabajo_antes = round(n/sum(n)*100,1)) |>
print(n = Inf) |>
arrange(desc(n)) |>
rename("cantidad_reos"=n)
# A partir de ello, se presenta a continuación un gráfico circular que permitirá observar la cantidad de reos que tuvieron a algún miembro de su familia preso en un establecimiento penitenciario.
table(CNPP_data$P133)
etiqueta_1 <- c(`1`="Sí",
`2`="No",
`3`="No recuerda/No contesta")
CNPP_data |>
mutate(P133 = recode_factor(P133,!!!etiqueta_1)) |>
count(P133) |>
mutate(
Porcentaje = round(n/sum(n)*100,1)) |>
ggplot() +
aes(x=1, y=Porcentaje, fill=P133) +
geom_bar(stat="identity") +
geom_text(aes(label = paste0(n,", ",round(Porcentaje,1),"%")),
position = position_stack(vjust = 0.5), size=3, fontface = "bold") +
coord_polar(theta = "y") +
theme_void() +
scale_fill_brewer(palette="Set1") +
labs(
title = "PERÚ: ¿ALGÚN MIEMBRO DE LA FAMILIA DEL REO PENITENCIARIO \nESTUVO PRESO EN UN ESTABLECIMIENTO PENITENCIARIO \nALGUNA VEZ?",
subtitle = "(Frecuencia, porcentaje)")
```
Como puede observarse, el 69.7% de los reos no tuvo a algún miembro de su familia preso en un establecimiento penitenciario; mientras que un 29.5% afirma que sí lo tuvo.
##### P135
**ANTES DE CUMPLIR LOS 18 AÑOS DE EDAD. ¿ALGUN(OS) DE SU(S) MEJOR(ES) AMIGO(S) COMETÍA(N) DELITOS?**
```{r, warning=FALSE, out.width = "100%", message=FALSE}
# Utilizando 'count' y 'mutate' hallamos la cantidad de reos que, antes de cumplir los 18 años de edad, tuvieron algún mejor amigo que cometía delitos, así como el porcentaje que representan respecto del total.
CNPP_data |>
count(P135) |>
mutate(Porcentaje_trabajo_antes = round(n/sum(n)*100,1)) |>
print(n = Inf) |>
arrange(desc(n)) |>
rename("cantidad_reos"=n)
# A partir de ello, se presenta a continuación un gráfico circular que permitirá observar la cantidad de reos que, antes de cumplir los 18 años de edad, tuvieron algún mejor amigo que cometía delitoso.
table(CNPP_data$P135)
etiqueta_1 <- c(`1`="Sí",
`2`="No",
`3`="No recuerda/No contesta")
CNPP_data |>
mutate(P135 = recode_factor(P135,!!!etiqueta_1)) |>
count(P135) |>
mutate(
Porcentaje = round(n/sum(n)*100,1)) |>
ggplot() +
aes(x=1, y=Porcentaje, fill=P135) +
geom_bar(stat="identity") +
geom_text(aes(label = paste0(n,", ",round(Porcentaje,1),"%")),
position = position_stack(vjust = 0.5), size=3, fontface = "bold") +
coord_polar(theta = "y") +
theme_void() +
scale_fill_brewer(palette="Set1") +
labs(
title = "PERÚ: ANTES DE QUE EL REO PENITENCIARIO CUMPLA \n18 AÑOS, ¿ALGUNO DE SUS MEJORES AMIGOS COMETÍAN \nDELITOS?",
subtitle = "(Frecuencia, porcentaje)")
```
Como puede observarse, el 65% de los reos señala que, antes de cumplir los 18 años de edad, no tuvieron algún mejor amigo que cometiera delitos; mientras que un 34% señala que sí lo tuvo.
##### P215
**¿USTED ESTUVO INTERNADO(A) EN ALGÚN CENTRO JUVENIL?**
```{r, warning=FALSE, out.width = "100%", message=FALSE}
table(CNPP_data$P215, useNA = "alw")
etiqueta_1 <- c(`1`="Sí",
`2`="No",
`3`="No sabe/No contesta")
CNPP_data$P215 <- as.factor(CNPP_data$P215)
CNPP_data |>
filter(!is.na(P215)) |>
mutate(P215 = recode_factor(P215,!!!etiqueta_1)) |>
count(P215) |>
mutate(
Porcentaje = round(n/sum(n)*100,1)) |>
ggplot() +
aes(x=1, y=Porcentaje, fill=P215) +
geom_bar(stat="identity") +
geom_text(aes(label = paste0(n,", ",round(Porcentaje,1),"%")),
position = position_stack(vjust = 0.5)) +
coord_polar(theta = "y") +
theme_void() +
scale_fill_brewer(palette="Set1") +
labs(
title = "PERÚ: POBLACIÓN PENITENCIARIA QUE ESTUVO \nINTERNADO(A) EN ALGÚN CENTRO JUVENIL",
subtitle = "(Frecuencia, porcentaje)"
)
```
El 91.8% de la población penitenciaria no estuvo internado en algún centro juvenil.
##### P220
**SIN TOMAR EN CUENTA LA SENTENCIA QUE ACTUALMENTE CUMPLE: ¿EN ALGUNA OTRA OCASIÓN LO HABÍAN SENTENCIADO O PROCESADO A PENA EFECTIVA POR ALGÚN OTRO DELITO?**
```{r, warning=FALSE, out.width = "100%", message=FALSE}
table(CNPP_data$P220, useNA = "alw")
etiqueta_1 <- c(`1`="Sí",
`2`="No",
`3`="No sabe/No contesta")
CNPP_data$P220 <- as.factor(CNPP_data$P220)
CNPP_data |>
filter(!is.na(P220)) |>
mutate(P220 = recode_factor(P220,!!!etiqueta_1)) |>
count(P220) |>
mutate(
Porcentaje = round(n/sum(n)*100,1)) |>
ggplot() +
aes(x=1, y=Porcentaje, fill=P220) +
geom_bar(stat="identity") +
geom_text(aes(label = paste0(n,", ",round(Porcentaje,1),"%")),
position = position_stack(vjust = 0.5)) +
coord_polar(theta = "y") +
theme_void() +
scale_fill_brewer(palette="Set1") +
labs(
title = "PERÚ: POBLACIÓN PENITENCIARIA QUE ESTUVO \nANTERIORMENTE SENTENCIADO O PROCESADO A PENA \nEFECTIVA POR ALGÚN OTRO DELITO",
subtitle = "(Frecuencia, porcentaje)"
)
```
El 16.6% de la población penitenciaria estuvo anteriormente sentenciado o procesado a pena efectiva por algún otro delito.
Además, la siguiente tabla muestra el establecimiento penitenciario a las que pertenecen los reos reincidentes.
```{r}
table(CNPP_data$EST_PENIT, CNPP_data$P220)
```
Se puede observar que el establecimiento penitenciario donde se encuentra la mayoría de reos reincidentes (opción 1) están en el E.P. de Lurigancho (1199 reos).
#### Durante: Contexto del delito y situación en el establecimiento penitenciario
##### DELITO_GENERICO
**Delitos genéricos**
```{r, warning=FALSE, out.width = "100%", message=FALSE}
delitos_var <- unique(CNPP_data$DELITO_GENERICO)
print(delitos_var)
```
Esta información muestra todos los tipos de delitos que han cometido las personas encuestadas y que se encluentran recluidas en los centros penitenciarios.
DELITOS GENÉRICOS ORDENADO POR ORDEN DE FRECUENCIA
```{r, warning=FALSE, out.width = "100%", message=FALSE}
tabla_delitos <- table(CNPP_data$DELITO_GENERICO)
df_DEL_GEN <- as.data.frame(tabla_delitos)
colnames(df_DEL_GEN) <- c("DELITO_GENERICO", "Frecuencia")
df_DEL_GEN <- df_DEL_GEN %>%
arrange(desc(Frecuencia))
print(df_DEL_GEN)
```
Se encuentra que el delito más cometido es el delito contra el patrimonio, seguido de la seguridad pública. En tercer lugar se encuentra el delito contra la libertad y cuarto es el delito contra la vida, el cuerpo y la salud.
**DELITO GENÉRICO COMETIDO POR CADA DEPARTAMENTO**
```{r, warning=FALSE, out.width = "100%", message=FALSE}
CNPP_data_filtered <- CNPP_data %>% #Filtrando el delito cometido sin NA o espacios
filter(!is.na(P201_DD) & P201_DD != "")
delitoxdep<- CNPP_data_filtered %>%
group_by(P201_DD, DELITO_GENERICO) %>%
summarize(Frecuencia = n()) %>%
slice(which.max(Frecuencia)) %>%
arrange(desc(Frecuencia))
print(delitoxdep)
```
Para profundizar el tipo de delitos, se realiza un análisis que muestra en el tipo de delitos que es más freucnete por cada departamento. En este sentido, se encuentra que el delito contra el patrimonio es el más cometido.
**DELITOS ESPECÍFICOS A PARTIR DEL DELITO MÁS COMETIDO**
```{r, warning=FALSE, out.width = "100%", message=FALSE}
CNPP_data_filtrado_delitos_patrimonio <- CNPP_data %>% #Se filtra un solo delito
filter(!is.na(DELITO_GENERICO) & DELITO_GENERICO == "DELITOS CONTRA EL PATRIMONIO")
#Tabla por delito específico
delitos_patrimonio <- CNPP_data_filtrado_delitos_patrimonio %>%
group_by(DELITO_ESPECIFICO) %>%
summarize(Frecuencia = n()) %>%
arrange(desc(Frecuencia))
print(delitos_patrimonio)
```
Se desagrega el delito de delitos contra el patrimonio para conocer cuáles son los tipos de delito que se comete con mayor frecuencia. Dicha información muestraque es el robo agravado el delito más cometido.
##### P107
**¿PADECE UD. DE: ENFERMEDADES CRÓNICAS? ¿PADECE UD. DE: ENFERMEDADES INFECTO CONTAGIOSAS? ¿PADECE UD. DE: OTRAS ENFERMEDADES?**
**-Enfermedades crónicas:** asma, bronquitis o enfisema, hipertensión, diabetes.
**-Enfermedades infecto contagiosas:** tuberculosis, infecciones de transmisión sexual, VIH/SIDA.
**-Otras enfermedades:** hepatitis, depresión, ansiedad, adicción a sustancias psicoactivas, cáncer, otro.
```{r, warning=FALSE, out.width = "100%", message=FALSE}
# A continuación se crea una nueva variable, denominada "enfermedades"; cuyo valor es "Sí" cuando el reo posee una enfermedad crónica, infecto contagiosa u otra.
# Para dicho fin, en primer lugar creamos una variable dicotómica por cada tipo de enfermedad (Crónica/Infecto contagiosa/Otra); en la cual, el valor de "1" significa que el reo tiene al menos una enfermedad del tipo respectivo.
CNPP_data <- CNPP_data |>
mutate(enfermedad_cronica = case_when(P107_1 == 1 | P107_2 == 1 | P107_3 == 1 ~ "1", TRUE ~ "2"))
CNPP_data <- CNPP_data |>
mutate(enfermedad_infecto_contagiosa = case_when(P107_4 == 1 | P107_5 == 1 | P107_6 == 1 ~ "1", TRUE ~ "2"))
CNPP_data <- CNPP_data |>
mutate(enfermedad_otra = case_when(P107_7 == 1 | P107_8 == 1 | P107_9 == 1 | P107_10 == 1 | P107_11 == 1 | P107_12 == 1 ~ "1", TRUE ~ "2"))
# Luego, creamos una nueva variable denominada 'enfermedades', que pueda resumir el tipo de enfermedad que tiene cada reo penitenciario.
CNPP_data <- CNPP_data |>
mutate(enfermedades = case_when(enfermedad_cronica == 1 & enfermedad_infecto_contagiosa == 2 & enfermedad_otra == 2 ~ "CRONICA", enfermedad_cronica == 2 & enfermedad_infecto_contagiosa == 1 & enfermedad_otra == 2 ~ "INFECTO CONTAGIOSA", enfermedad_cronica == 2 & enfermedad_infecto_contagiosa == 2 & enfermedad_otra == 1 ~ "OTRA", enfermedad_cronica == 1 & enfermedad_infecto_contagiosa == 1 & enfermedad_otra == 2 ~ "CRONICA E INFECTO CONTAGIOSA", enfermedad_cronica == 1 & enfermedad_infecto_contagiosa == 2 & enfermedad_otra == 1 ~ "CRONICA Y OTRA", enfermedad_cronica == 2 & enfermedad_infecto_contagiosa == 1 & enfermedad_otra == 1 ~ "INFECTO CONTAGIOSA Y OTRA", enfermedad_cronica == 1 & enfermedad_infecto_contagiosa == 1 & enfermedad_otra == 1 ~ "CRONICA, INFECTO CONTAGIOSA Y OTRO", enfermedad_cronica == 2 & enfermedad_infecto_contagiosa == 2 & enfermedad_otra == 2 ~ "NINGUNA/NO SABE/NO RESPONDE"))
# Utilizando 'count' y 'mutate' hallamos la cantidad de reos que poseen cierto tipo de enfermedad, así como el porcentaje que representan respecto del total.
CNPP_data |>
count(enfermedades) |>
mutate(Porcentaje_enfermedades = round(n/sum(n)*100,1)) |>
print(n = Inf) |>
arrange(desc(n)) |>
rename("cantidad_reos"=n)
# A partir de la variable obtenida ('enfermedades'), se presenta a continuación un gráfico de barras que permitirá observar la cantidad de reos que poseen cierto tipo de enfermedad.
library(ggplot2)
CNPP_data |>
mutate(enfermedades = recode_factor(enfermedades, !!!etiqueta_1)) |>
count(enfermedades) |>
ggplot() +
aes(x = enfermedades, y = n, fill = enfermedades) +
geom_col(position = "dodge", width = 0.8) +
geom_text(aes(label = n),
position = position_dodge(width = 0.8), vjust = -0.5, size = 3, fontface = "bold") +
theme_minimal() +
scale_fill_brewer(palette = "Set1") +
labs(
title = "PERÚ: POBLACIÓN PENITENCIARIA QUE PADECE \nDE ALGUNA ENFERMEDAD",
subtitle = "(Frecuencia)",
x = "Enfermedades",
y = "Frecuencia")+
theme(axis.text.x = element_blank())
```
Como puede observarse, un gran número de reos señala que no tiene ninguna enfermedad, o no sabe, o no responde a la pregunta realizada. En segundo lugar, 12,370 reos mencionan que tienen otro tipo de enfermedad (hepatitis, depresión, ansiedad, adicción a sustancias psicoactivas, cáncer, otro); seguido por aquellos que tienen una enfermedad crónica (asma, bronquitis o enfisema, hipertensión, diabetes).
##### P201_DD
**DEPARTAMENTO EN EL QUE OCURRIO EL DELITO**
```{r, warning=FALSE, out.width = "100%", message=FALSE}
# CNPP_data |>
# count(P201_DD) |> #count para contar la cantidad de casos.
# mutate(Porcentaje = round(n/sum(n)*100,1)) |> #Mutate crea la variable porcentaje.
# print(n = Inf) |>
# arrange(desc(n))
#Importar las librerías para el mapa
library(plotly)
library(mapsPERU)
library(tidyverse)
library(ggrepel)
library(haven)
library(leaflet)
library(leaflet.extras)
library(rworldxtra)
library(raster)
library(sf)
#Extraemos las coordenadas del paquete mapsPERU departamento
df <- map_DEP
#convertimos todas las variables que tenga caracteres
#de minúscula a mayúsculas.
df <- mutate_if(df, is.character, toupper)
#Quitamos las tildes de las mayúsculas
df$DEPARTAMENTO <- chartr('Á,É,Í,Ó,Ú','A,E,I,O,U', df$DEPARTAMENTO)
#Renombramos la variable P201_DD de la base CNPP_data
df_total_mapa <- rename(CNPP_data, DEPARTAMENTO = P201_DD)
#Extraemos los datos de interés para el mapa
Delito_depart <- df_total_mapa |>
count(DEPARTAMENTO) |> #count para contar la cantidad de casos.
mutate(Porcentaje = round(n/sum(n)*100,1)) |> #Mutate crea la variable porcentaje.
print(n = Inf) |>
arrange(desc(n))
#Integramos ambas bases de datos a través de DEPARTAMENTO
mapa_delitos <- left_join(df, Delito_depart, by = "DEPARTAMENTO")
#Creamos la base del mapa
leaflet() |> addTiles() |> addCircleMarkers(data = mapa_delitos, lat = ~coords_y, radius = ~Porcentaje,
lng = ~coords_x, color = "red",
fillOpacity = 3, label = ~n, labelOptions(permanent=TRUE) )
```
El mapa permite identificar rápidamente el departamento donde ocurrió la mayor cantidad de delitos (22793 delitos) la cual corresponde a Lima; y la de menor cantidad, (464 delitos) a Huancavelica.
##### P204
**CUANDO OCURRIÓ EL DELITO, ¿USTED USÓ ALGÚN ARMA?**
```{r, warning=FALSE, out.width = "100%", message=FALSE}
CNPP_data |>
filter(!is.na(P204)) |>
count(P204) |>
mutate(Porcentaje = round(n/sum(n)*100,1)) |>
print(n = Inf)
table(CNPP_data$P204, useNA = "alw")
etiqueta_1 <- c(`1`="Sí",
`2`="No",
`3`="No sabe/No contesta")
CNPP_data$P204 <- as.factor(CNPP_data$P204)
CNPP_data |>
filter(!is.na(P204)) |>
mutate(P204 = recode_factor(P204,!!!etiqueta_1)) |>
count(P204) |>
mutate(
Porcentaje = round(n/sum(n)*100,1)) |>
ggplot() +
aes(x=1, y=Porcentaje, fill=P204) +
geom_bar(stat="identity") +
geom_text(aes(label = paste0(n,", ",round(Porcentaje,1),"%")),
position = position_stack(vjust = 0.5)) +
coord_polar(theta = "y") +
theme_void() +
scale_fill_brewer(palette="Set1") +
labs(
title = "PERÚ: POBLACIÓN PENITENCIARIA QUE UTILIZÓ UN ARMA \nCUANDO OCURRIÓ EL DELITO",
subtitle = "(Frecuencia, porcentaje)"
)