library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(dplyr)
library(readr)
library(ggplot2)
library(readxl)
Para el análisis de datos sobre producción, rendimiento o área cosechada de un grupo de cultivo de interes en un intervalo de tiempo (2006-2018), es necesario consultar la base de datos que reposa en la evaluaciones agropecuarias municipales para el departamento de Norte de santander. Con ayuda de diagramas de barras y de tortas se presenta la información de manera más didactica para el correcto análisis y conclusión.
(eva = read_csv("C:/Users/andre/OneDrive/Escritorio/Documentos U/12 matricula/Geomatica/Proyectos/Evaluaciones_Agropecuarias_Municipales_EVA.csv", col_names = TRUE))
## Rows: 9751 Columns: 17
## -- Column specification --------------------------------------------------------
## Delimiter: ","
## chr (10): DEPARTAMENTO, MUNICIPIO, GRUPO
## DE CULTIVO, SUBGRUPO
## DE CULTIVO, ...
## dbl (7): CÓD.
## DEP., CÓD. MUN., AÑO, Área Sembrada
## (ha), Área Cosechada
## (ha...
##
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
## # A tibble: 9,751 x 17
## `CÓD. \nDEP.` DEPARTAMENTO `CÓD. MUN.` MUNICIPIO `GRUPO \nDE CULTIVO`
## <dbl> <chr> <dbl> <chr> <chr>
## 1 54 NORTE DE SANTANDER 54405 LOS PATIOS HORTALIZAS
## 2 54 NORTE DE SANTANDER 54518 PAMPLONA HORTALIZAS
## 3 54 NORTE DE SANTANDER 54518 PAMPLONA HORTALIZAS
## 4 54 NORTE DE SANTANDER 54405 LOS PATIOS HORTALIZAS
## 5 54 NORTE DE SANTANDER 54518 PAMPLONA HORTALIZAS
## 6 54 NORTE DE SANTANDER 54405 LOS PATIOS HORTALIZAS
## 7 54 NORTE DE SANTANDER 54518 PAMPLONA HORTALIZAS
## 8 54 NORTE DE SANTANDER 54405 LOS PATIOS HORTALIZAS
## 9 54 NORTE DE SANTANDER 54518 PAMPLONA HORTALIZAS
## 10 54 NORTE DE SANTANDER 54405 LOS PATIOS HORTALIZAS
## # ... with 9,741 more rows, and 12 more variables:
## # `SUBGRUPO \nDE CULTIVO` <chr>, CULTIVO <chr>,
## # `DESAGREGACIÓN REGIONAL Y/O SISTEMA PRODUCTIVO` <chr>, AÑO <dbl>,
## # PERIODO <chr>, `Área Sembrada\n(ha)` <dbl>, `Área Cosechada\n(ha)` <dbl>,
## # `Producción\n(t)` <dbl>, `Rendimiento\n(t/ha)` <dbl>,
## # `ESTADO FISICO PRODUCCION` <chr>, `NOMBRE \nCIENTIFICO` <chr>,
## # `CICLO DE CULTIVO` <chr>
names(eva)
## [1] "CÓD. \nDEP."
## [2] "DEPARTAMENTO"
## [3] "CÓD. MUN."
## [4] "MUNICIPIO"
## [5] "GRUPO \nDE CULTIVO"
## [6] "SUBGRUPO \nDE CULTIVO"
## [7] "CULTIVO"
## [8] "DESAGREGACIÓN REGIONAL Y/O SISTEMA PRODUCTIVO"
## [9] "AÑO"
## [10] "PERIODO"
## [11] "Área Sembrada\n(ha)"
## [12] "Área Cosechada\n(ha)"
## [13] "Producción\n(t)"
## [14] "Rendimiento\n(t/ha)"
## [15] "ESTADO FISICO PRODUCCION"
## [16] "NOMBRE \nCIENTIFICO"
## [17] "CICLO DE CULTIVO"
Como la tabla presenta atributos que pueden ser de poca importancia, es posible removerlos
## # A tibble: 9,751 x 13
## `CÓD. MUN.` MUNICIPIO `GRUPO \nDE CULTIVO` `SUBGRUPO \nDE CULTIVO` CULTIVO
## <dbl> <chr> <chr> <chr> <chr>
## 1 54405 LOS PATIOS HORTALIZAS ACELGA ACELGA
## 2 54518 PAMPLONA HORTALIZAS ACELGA ACELGA
## 3 54518 PAMPLONA HORTALIZAS ACELGA ACELGA
## 4 54405 LOS PATIOS HORTALIZAS ACELGA ACELGA
## 5 54518 PAMPLONA HORTALIZAS ACELGA ACELGA
## 6 54405 LOS PATIOS HORTALIZAS ACELGA ACELGA
## 7 54518 PAMPLONA HORTALIZAS ACELGA ACELGA
## 8 54405 LOS PATIOS HORTALIZAS ACELGA ACELGA
## 9 54518 PAMPLONA HORTALIZAS ACELGA ACELGA
## 10 54405 LOS PATIOS HORTALIZAS ACELGA ACELGA
## # ... with 9,741 more rows, and 8 more variables:
## # `DESAGREGACIÓN REGIONAL Y/O SISTEMA PRODUCTIVO` <chr>, AÑO <dbl>,
## # PERIODO <chr>, `Área Sembrada\n(ha)` <dbl>, `Área Cosechada\n(ha)` <dbl>,
## # `Producción\n(t)` <dbl>, `Rendimiento\n(t/ha)` <dbl>,
## # `ESTADO FISICO PRODUCCION` <chr>
Para continuar con la limpieza, se pueden cambiar los nombres de los atributos
eva.tmp %>% dplyr::rename('Cod_Mun' = 'CÓD. MUN.',
'Grupo' = 'GRUPO \nDE CULTIVO',
'Subgrupo' = 'SUBGRUPO \nDE CULTIVO',
'Year' = 'AÑO',
'AreaSembrada' = 'Área Sembrada\n(ha)',
'AreaCosechada' = 'Área Sembrada\n(ha)',
'Produccion' = 'Producción\n(t)', 'Rendimiento' = 'Rendimiento\n(t/ha)',
'Sistema' = 'DESAGREGACIÓN REGIONAL Y/O SISTEMA PRODUCTIVO',
'Estado' = 'ESTADO FISICO PRODUCCION') -> new_eva
new_eva
## # A tibble: 9,751 x 13
## Cod_Mun MUNICIPIO Grupo Subgrupo CULTIVO Sistema Year PERIODO AreaCosechada
## <dbl> <chr> <chr> <chr> <chr> <chr> <dbl> <chr> <dbl>
## 1 54405 LOS PATIOS HORT~ ACELGA ACELGA ACELGA 2006 2006B 3
## 2 54518 PAMPLONA HORT~ ACELGA ACELGA ACELGA 2006 2006B 1
## 3 54518 PAMPLONA HORT~ ACELGA ACELGA ACELGA 2007 2007A 1
## 4 54405 LOS PATIOS HORT~ ACELGA ACELGA ACELGA 2007 2007B 3
## 5 54518 PAMPLONA HORT~ ACELGA ACELGA ACELGA 2007 2007B 1
## 6 54405 LOS PATIOS HORT~ ACELGA ACELGA ACELGA 2008 2008A 3
## 7 54518 PAMPLONA HORT~ ACELGA ACELGA ACELGA 2008 2008A 1
## 8 54405 LOS PATIOS HORT~ ACELGA ACELGA ACELGA 2008 2008B 3
## 9 54518 PAMPLONA HORT~ ACELGA ACELGA ACELGA 2008 2008B 1
## 10 54405 LOS PATIOS HORT~ ACELGA ACELGA ACELGA 2009 2009A 2
## # ... with 9,741 more rows, and 4 more variables: `Área Cosechada\n(ha)` <dbl>,
## # Produccion <dbl>, Rendimiento <dbl>, Estado <chr>
Después de haber realizado la limpieza y procesamiento de la base de datos correspondiente a la evaluación agropecuaria municipal, es posible identificar los grupos de cultivos más importantes en el departamento de Norte de Santander y el total de la producción.
new_eva %>%
filter(Produccion > 0) %>%
group_by(Grupo) %>%
summarize(total_produccion = sum(Produccion)) %>%
arrange(desc(total_produccion)) -> pt
pt
## # A tibble: 11 x 2
## Grupo total_produccion
## <chr> <dbl>
## 1 TUBERCULOS Y PLATANOS 3564160
## 2 HORTALIZAS 2188261
## 3 CEREALES 2107524
## 4 OTROS PERMANENTES 1015639
## 5 FRUTALES 948593
## 6 OLEAGINOSAS 712280
## 7 LEGUMINOSAS 153888
## 8 OTROS TRANSITORIOS 11087
## 9 PLANTAS AROMATICAS, CONDIMENTARIAS Y MEDICINALES 4587
## 10 FIBRAS 660
## 11 FLORES Y FOLLAJES 247
Con la anterior información es posible filtar los grupos de cultivos más importantes, saber el total de producción y adicionar el porcentaje de producción como un nuevo atributo
pt %>% filter(total_produccion > 1000000) -> main.groups
(value = sum(main.groups$total_produccion))
## [1] 8875584
main.groups$percent = main.groups$total_produccion/value
Para una mejor visualización de los grupos de cultivos más importantes del departamento Norte de Santander, se pueden separar por porcentaje
bp<- ggplot(main.groups, aes(x="", y=percent, fill=Grupo))+
geom_bar(stat = "identity")+geom_text(aes(label = paste0(round(percent,2),"%")),position = position_stack(vjust = 0.5))
pie <- bp + coord_polar(theta = "y")+theme_void()+scale_fill_brewer(palette = "Spectral")
pie
new_eva %>%
group_by(Grupo, MUNICIPIO) %>%
summarize(total_prod = sum(Produccion, na.rm = TRUE)) %>%
slice(which.max(total_prod)) %>%
arrange(desc(total_prod)) -> leaders
## `summarise()` has grouped output by 'Grupo'. You can override using the
## `.groups` argument.
leaders
## # A tibble: 12 x 3
## # Groups: Grupo [12]
## Grupo MUNICIPIO total_prod
## <chr> <chr> <dbl>
## 1 CEREALES CUCUTA 1324179
## 2 HORTALIZAS OCAÑA 828289
## 3 TUBERCULOS Y PLATANOS TIBU 582127
## 4 OLEAGINOSAS TIBU 480110
## 5 OTROS PERMANENTES EL ZULIA 162291
## 6 FRUTALES TEORAMA 91710
## 7 LEGUMINOSAS OCAÑA 29918
## 8 OTROS TRANSITORIOS ABREGO 10067
## 9 PLANTAS AROMATICAS, CONDIMENTARIAS Y MEDICINALES VILLA DEL ROSARIO 2860
## 10 FIBRAS CUCUTILLA 467
## 11 FLORES Y FOLLAJES PAMPLONA 240
## 12 FORESTALES TIBU 0
Filtrando el total de producción de cada departamento es posible construir una gráfica de barras que nos muestre el aporte en producción de cada municio de Norte de Santander
leaders %>% filter(total_prod > 50000) -> main.leaders
p<-ggplot(data=main.leaders, aes(x=MUNICIPIO, y=total_prod)) +
geom_bar(stat="identity", fill="Red4")+theme_light()
p
Para éste caso, el arroz (grupo de cereales) es el de mayor producción en el municipio de Cúcuta, Norte de Santander
new_eva %>%
filter(MUNICIPIO=="CUCUTA" & CULTIVO=="ARROZ") %>%
group_by(Year, CULTIVO) %>%
select(MUNICIPIO, CULTIVO, Produccion, Year) -> cucuta_arroz
cucuta_arroz
## # A tibble: 24 x 4
## # Groups: Year, CULTIVO [13]
## MUNICIPIO CULTIVO Produccion Year
## <chr> <chr> <dbl> <dbl>
## 1 CUCUTA ARROZ 51000 2006
## 2 CUCUTA ARROZ 54000 2007
## 3 CUCUTA ARROZ 49770 2007
## 4 CUCUTA ARROZ 56700 2008
## 5 CUCUTA ARROZ 63647 2008
## 6 CUCUTA ARROZ 70700 2009
## 7 CUCUTA ARROZ 79000 2009
## 8 CUCUTA ARROZ 60000 2010
## 9 CUCUTA ARROZ 45000 2010
## 10 CUCUTA ARROZ 65170 2011
## # ... with 14 more rows
g <- ggplot(aes(x=Year, y=Produccion/1000), data = cucuta_arroz) + geom_bar(stat='identity', fill="Red4") + labs(y='Produccion de arroz [Ton x 1000]') + theme_light()
g + ggtitle("Evolución de la producción del cultivo de arroz en Cúcuta del 2006 al 2018") + labs(caption= "Based on EVA data (Minagricultura, 2020)")
new_eva %>%
filter(MUNICIPIO=="CUCUTA" & CULTIVO=="ARROZ") %>%
group_by(Year, CULTIVO) %>%
select(MUNICIPIO, CULTIVO, AreaCosechada, Year) -> Area_cucuta_arroz
Area_cucuta_arroz
## # A tibble: 24 x 4
## # Groups: Year, CULTIVO [13]
## MUNICIPIO CULTIVO AreaCosechada Year
## <chr> <chr> <dbl> <dbl>
## 1 CUCUTA ARROZ 8100 2006
## 2 CUCUTA ARROZ 8660 2007
## 3 CUCUTA ARROZ 7948 2007
## 4 CUCUTA ARROZ 9180 2008
## 5 CUCUTA ARROZ 11720 2008
## 6 CUCUTA ARROZ 10310 2009
## 7 CUCUTA ARROZ 11300 2009
## 8 CUCUTA ARROZ 9500 2010
## 9 CUCUTA ARROZ 8444 2010
## 10 CUCUTA ARROZ 12000 2011
## # ... with 14 more rows
g <- ggplot(aes(x=Year, y=AreaCosechada/1000), data = Area_cucuta_arroz) + geom_bar(stat='identity', fill="Red4") + labs(y='Area cosechada de arroz [Ha]') + theme_light()
g + ggtitle("Evolución del área cosechada del cultivo de arroz en Cúcuta del 2006 al 2018") + labs(caption= "Based on EVA data (Minagricultura, 2020)")