Pacakges usados

library(tidyverse)
library(rgdal)
library(sf)
library(mapview)
library(reshape2)
library(kableExtra)

Importación del archivo EVA

df_eva_aru = read.csv('../../arauca/documents/EVA_arauca.csv',
                      encoding = 'UTF-8')
colnames(df_eva_aru) = c('cod_DPTO', 'nmbr_DPTO', 'cod_MPIO', 'nmbr_MPIO',
                         'grupo_cultivo', 'subgrupo_cultivo', 'cultivo', 'sistema_productivo',
                         'AÑO', 'PERIODO',
                         'area_sembrada_ha', 'area_cosechada_ha', 'produccion_t', 'rendimiento_t_ha',
                         'estado_produc', 'nombre_cientifico', 'ciclo_cultivo')

df_eva_aru$nmbr_MPIO = str_replace_all(df_eva_aru$nmbr_MPIO, 'RONDON', 'RONDÓN')

df_eva_aru = df_eva_aru %>% 
  filter(AÑO > 2006) %>% 
  mutate(cultivo = as.factor(cultivo),
         nmbr_MPIO = as.factor(nmbr_MPIO),
         AÑO_num = AÑO,
         AÑO = as.factor(AÑO))
str(df_eva_aru)
## 'data.frame':    845 obs. of  18 variables:
##  $ cod_DPTO          : int  81 81 81 81 81 81 81 81 81 81 ...
##  $ nmbr_DPTO         : chr  "ARAUCA" "ARAUCA" "ARAUCA" "ARAUCA" ...
##  $ cod_MPIO          : int  81065 81794 81065 81300 81736 81794 81065 81300 81736 81794 ...
##  $ nmbr_MPIO         : Factor w/ 7 levels "ARAUCA","ARAUQUITA",..: 2 7 2 4 6 7 2 4 6 7 ...
##  $ grupo_cultivo     : chr  "PLANTAS AROMATICAS, CONDIMENTARIAS Y MEDICINALES" "FRUTALES" "FRUTALES" "FRUTALES" ...
##  $ subgrupo_cultivo  : chr  "PLANTAS CONDIMENTARIAS" "AGUACATE" "AGUACATE" "AGUACATE" ...
##  $ cultivo           : Factor w/ 18 levels "ACHIOTE","AGUACATE",..: 1 2 2 2 2 2 2 2 2 2 ...
##  $ sistema_productivo: chr  "ACHIOTE (BIJA)" "AGUACATE" "AGUACATE" "AGUACATE" ...
##  $ AÑO               : Factor w/ 12 levels "2007","2008",..: 1 6 6 6 6 7 7 7 7 8 ...
##  $ PERIODO           : chr  "2007" "2012" "2012" "2012" ...
##  $ area_sembrada_ha  : int  285 170 60 45 27 162 62 48 37 162 ...
##  $ area_cosechada_ha : int  285 65 25 38 20 80 30 30 20 100 ...
##  $ produccion_t      : int  265 975 375 570 400 1200 450 450 400 1500 ...
##  $ rendimiento_t_ha  : num  0.93 15 15 15 20 15 15 15 20 15 ...
##  $ estado_produc     : chr  "TUBERCULO FRESCO" "FRUTO FRESCO" "FRUTO FRESCO" "FRUTO FRESCO" ...
##  $ nombre_cientifico : chr  "BIXA ORELLANA" "PERSEA AMERICANA MILL." "PERSEA AMERICANA MILL." "PERSEA AMERICANA MILL." ...
##  $ ciclo_cultivo     : chr  "ANUAL" "PERMANENTE" "PERMANENTE" "PERMANENTE" ...
##  $ AÑO_num           : int  2007 2012 2012 2012 2012 2013 2013 2013 2013 2014 ...

Importación del archivo ShapeFile de municipios para el departamento de Arauca

shp_aru = readOGR('../../arauca/81_ARAUCA/ADMINISTRATIVO/MGN_MPIO_POLITICO.shp',
                  encoding = 'UTF-8', use_iconv = T)
## OGR data source with driver: ESRI Shapefile 
## Source: "C:\Users\ADMIN\Documentos\CARLOS\UNAL\Asignaturas\Geomatica\arauca\81_ARAUCA\ADMINISTRATIVO\MGN_MPIO_POLITICO.shp", layer: "MGN_MPIO_POLITICO"
## with 7 features
## It has 10 fields
shp_aru
## class       : SpatialPolygonsDataFrame 
## features    : 7 
## extent      : -72.36662, -69.42756, 6.036228, 7.104381  (xmin, xmax, ymin, ymax)
## crs         : +proj=longlat +datum=WGS84 +no_defs 
## variables   : 10
## names       : DPTO_CCDGO, MPIO_CCDGO, MPIO_CNMBR,                           MPIO_CRSLC,    MPIO_NAREA, MPIO_NANO, DPTO_CNMBR,    Shape_Leng,    Shape_Area,        Area 
## min values  :         81,      81001,     ARAUCA,                                 1959,  945.13540708,      2017,     ARAUCA, 1.29412603421, 0.07721412676, 943718678.3 
## max values  :         81,      81794,       TAME, Decreto Nal 677 de Abril 13 de  1987, 5787.94213047,      2017,     ARAUCA, 4.66801606458, 0.47162611666,  5765552712

Estadisticas EVA - Arauca

df_eva_aru %>% 
  select(cultivo, AÑO) %>% 
  unique() %>% 
  group_by(AÑO) %>% 
  summarise(n_cultivos = n()) %>% 
  ggplot()+
  aes(AÑO, n_cultivos)+
  geom_col()+
  labs(y = 'Numero de cultivos')+
  theme_bw()+
  theme(text = element_text(size=18))

# Principales cultivos segun ENA (Maiz, Yuca, Cacao, Platano)
df_eva_aru %>% 
  group_by(AÑO, cultivo, nmbr_MPIO) %>% 
  summarise(area_semb_max = max(area_sembrada_ha)) %>% 
  summarise(area_semb_tot = sum(area_semb_max)) %>% 
  top_n(4, area_semb_tot) %>% 
  ggplot()+
  aes(AÑO, area_semb_tot, fill = cultivo)+
  geom_col(position = 'dodge')+
  scale_fill_brewer(palette = "Set1")+
  labs(y = 'Area sembrada (ha)')+
  theme_bw()+
  theme(text = element_text(size=18))

# cultivos_sel = c('ARROZ', 'CACAO', 'MAIZ', 'PLATANO', 'YUCA')
# df_eva_aru %>%
#   filter(cultivo %in% cultivos_sel) %>%
#   group_by(AÑO_num, cultivo, nmbr_MPIO) %>%
#   summarise(area_semb_max = max(area_sembrada_ha)) %>%
#   summarise(area_semb_tot = sum(area_semb_max)) %>%
#   # top_n(4, area_semb_tot) %>%
#   ggplot()+
#   aes(cultivo, area_semb_tot, fill = cultivo)+
#   geom_col(position = 'dodge')+
#   gganimate::transition_time(AÑO_num) +
#   scale_fill_brewer(palette = "Set1")+
#   labs(y = 'Area sembrada (ha)',
#        title = 'Año: {frame_time}')+
#   theme_bw()+
#   theme(text = element_text(size=18))

animación 1

\[\frac{\text{Área cosechada}}{\text{Área sembrada}}*100\]

cultivos_sel = c('ARROZ', 'CACAO', 'MAIZ', 'PLATANO', 'YUCA')

options(knitr.kable.NA = '')
df_porc_cos = df_eva_aru %>% 
  filter(cultivo %in% cultivos_sel) %>% 
  group_by(AÑO, cultivo, nmbr_MPIO) %>% 
  summarise(area_semb_max = max(area_sembrada_ha),
            area_cose_max = max(area_cosechada_ha)) %>% 
  summarise(area_semb_tot = sum(area_semb_max),
            area_cose_tot = sum(area_cose_max),
            porc_area = 100 * area_cose_tot/area_semb_tot)
df_porc_cos %>% 
  mutate(porc_area_tex = paste0(round(porc_area,1), ' %')) %>% 
  select(AÑO, cultivo, porc_area_tex) %>% 
  dcast('cultivo ~ AÑO') %>% 
  kbl() %>% 
  kable_paper("hover", full_width = F, font_size = 20)
cultivo 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018
ARROZ 96 % 100 % 99.9 % 99.6 % 97.5 % 98.4 % 91.2 % 99.1 % 92.1 % 98.4 % 100 % 100 %
CACAO 77.5 % 76.7 % 83.5 % 83.4 % 87 % 83.3 % 80.9 % 80.6 % 76.2 % 72.6 % 91.5 % 95.2 %
MAIZ 97.6 % 99.3 % 99.7 % 99.3 % 98.5 % 95.4 % 94.2 % 95.9 % 95.4 % 96.9 % 94.4 % 100 %
PLATANO 73.4 % 85.9 % 77.1 % 81.6 % 87.7 % 91.1 % 88.4 % 92.8 % 97.4 % 90 % 81.2 % 79.8 %
YUCA 93.7 % 81.9 % 97.5 % 96.3 % 96.2 % 97.1 % 92.6 % 89.6 % 95.5 % 93.2 % 89.5 % 99.8 %
df_porc_cos %>% 
  group_by(AÑO) %>% 
  summarise(media_porc_area = mean(porc_area)) %>% 
  mutate(porc_area_tex = paste0(round(media_porc_area,1), ' %')) %>% 
  select(AÑO, porc_area_tex) %>% 
  dcast('. ~ AÑO') %>% 
  select(-.) %>% 
  kbl() %>% 
  kable_paper("hover", full_width = F, font_size = 20)
2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018
87.6 % 88.8 % 91.5 % 92 % 93.4 % 93 % 89.5 % 91.6 % 91.3 % 90.2 % 91.3 % 95 %
# Cultivos de mayor producción en cada municipio por año
df_eva_aru %>% 
  filter(cultivo %in% cultivos_sel) %>% 
  group_by(AÑO, cultivo, nmbr_MPIO) %>% 
  summarise(prod_tot = sum(produccion_t)) %>%  
  mutate(porc_prod_tot = prod_tot/sum(prod_tot)) %>% 
  # top_n(2, prod_tot) %>% 
  ggplot()+
  aes(AÑO, porc_prod_tot, fill = nmbr_MPIO)+
  geom_col()+
  # geom_bar(position="fill", stat="identity")+
  facet_wrap(~cultivo, nrow=1)+
  scale_fill_brewer(palette = "Set1")+
  labs(y = 'Participación en la produccion (%)')+
  scale_y_continuous(labels = scales::percent)+
  theme_bw()+
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5),
        text = element_text(size=18))

# df_eva_aru %>%
#   filter(cultivo %in% cultivos_sel) %>%
#   group_by(AÑO_num, cultivo, nmbr_MPIO) %>%
#   summarise(prod_tot = sum(produccion_t)) %>%
#   mutate(porc_prod_tot = prod_tot/sum(prod_tot)) %>%
#   ggplot()+
#   aes(cultivo, porc_prod_tot, fill = nmbr_MPIO)+
#   geom_col()+
#   scale_fill_brewer(palette = "Set1")+
#   labs(y = 'Participación en la produccion (%)',
#        title = 'Año: {frame_time}')+
#   gganimate::transition_time(AÑO_num) +
#   scale_y_continuous(labels = scales::percent)+
#   theme_bw()+
#   theme(axis.text.x = element_text(angle = 90),
#         text = element_text(size=18))

Animación porcentaje de participación de cada municipio por año

Generación de mapas de rendimiento

centroides_aru = as.data.frame(coordinates(shp_aru))
colnames(centroides_aru) = c('long', 'lat')
shp_aru@data = shp_aru@data %>%
  bind_cols(centroides_aru)
df_res_rend = df_eva_aru %>%
  filter(cultivo %in% cultivos_sel) %>%
  group_by(AÑO, nmbr_MPIO, cultivo) %>%
  summarise(rendimiento_med = mean(rendimiento_t_ha, na.rm=T)) %>% 
  ungroup() %>% 
  complete(AÑO,nmbr_MPIO, nesting(cultivo))

df_spatial = st_as_sf(shp_aru) %>%
  left_join(df_res_rend, c('MPIO_CNMBR' = 'nmbr_MPIO'))
c_s = cultivos_sel[1]
df_spatial %>%
  filter(cultivo == c_s) %>% 
  ggplot()+
  geom_sf(aes(fill = rendimiento_med))+
  geom_text(aes(long, lat, label = MPIO_CNMBR), size = 3)+
  scale_fill_gradient(low = "#e9bd3a", high = "#00a600",
                      na.value = '#dbdbdb',
                      guide = guide_colorbar(barwidth = 30))+
  facet_wrap(~ AÑO, ncol=3)+
  labs(title = c_s, fill = 'Rendimiento medio (ton/ha)',
       x = 'Longitud', y = 'Latitud')+
  theme_bw()+
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5),
        legend.position = 'top',
        text = element_text(size=18))

c_s = cultivos_sel[2]
df_spatial %>%
  filter(cultivo == c_s) %>% 
  ggplot()+
  geom_sf(aes(fill = rendimiento_med))+
  geom_text(aes(long, lat, label = MPIO_CNMBR), size = 3)+
  scale_fill_gradient(low = "#e9bd3a", high = "#00a600",
                      na.value = '#dbdbdb',
                      guide = guide_colorbar(barwidth = 30))+
  facet_wrap(~ AÑO, ncol=3)+
  labs(title = c_s, fill = 'Rendimiento medio (ton/ha)',
       x = 'Longitud', y = 'Latitud')+
  theme_bw()+
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5),
        legend.position = 'top',
        text = element_text(size=18))

c_s = cultivos_sel[3]
df_spatial %>%
  filter(cultivo == c_s) %>% 
  ggplot()+
  geom_sf(aes(fill = rendimiento_med))+
  geom_text(aes(long, lat, label = MPIO_CNMBR), size = 3)+
  scale_fill_gradient(low = "#e9bd3a", high = "#00a600",
                      na.value = '#dbdbdb',
                      guide = guide_colorbar(barwidth = 30))+
  facet_wrap(~ AÑO, ncol=3)+
  labs(title = c_s, fill = 'Rendimiento medio (ton/ha)',
       x = 'Longitud', y = 'Latitud')+
  theme_bw()+
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5),
        legend.position = 'top',
        text = element_text(size=18))

c_s = cultivos_sel[4]
df_spatial %>%
  filter(cultivo == c_s) %>% 
  ggplot()+
  geom_sf(aes(fill = rendimiento_med))+
  geom_text(aes(long, lat, label = MPIO_CNMBR), size = 3)+
  scale_fill_gradient(low = "#e9bd3a", high = "#00a600",
                      na.value = '#dbdbdb',
                      guide = guide_colorbar(barwidth = 30))+
  facet_wrap(~ AÑO, ncol=3)+
  labs(title = c_s, fill = 'Rendimiento medio (ton/ha)',
       x = 'Longitud', y = 'Latitud')+
  theme_bw()+
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5),
        legend.position = 'top',
        text = element_text(size=18))

c_s = cultivos_sel[5]
df_spatial %>%
  filter(cultivo == c_s) %>% 
  ggplot()+
  geom_sf(aes(fill = rendimiento_med))+
  geom_text(aes(long, lat, label = MPIO_CNMBR), size = 3)+
  scale_fill_gradient(low = "#e9bd3a", high = "#00a600",
                      na.value = '#dbdbdb',
                      guide = guide_colorbar(barwidth = 30))+
  facet_wrap(~ AÑO, ncol=3)+
  labs(title = c_s, fill = 'Rendimiento medio (ton/ha)',
       x = 'Longitud', y = 'Latitud')+
  theme_bw()+
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5),
        legend.position = 'top',
        text = element_text(size=18))

Mapa del área municipal en el departamento de Arauca - Elavorado en QGis

Mapa municipio de Arauca - imagen desde el proyecto en QGIS

Link al projecto QGis