Introducción

El presente cuaderno busca ilustrar las estadísticas agricolas para el departamento de Antioquia en Colombia, que permita una mejor comprensión de la aplicación de conceptos de geomática en la agronomía.

Una aplicación útil es la exploración de estadísticas no espaciales posibilitando una mejor interpretación de lo que ocurre en nuestros territorios. Algunas bibliotecas utilizadas para explorar y resumir dichas estadísticas son dplyr y tidyverse.

Por otra parte, las operaciones geoespaciales nos ayudan a comprender problemáticas de las regiones geográficas, como por ejemplo la ubicación de municipios con mejor producción o rendimiento. Para hacer este análisis, se requiere unir datos espaciales con no espaciales. Adicionalmente, se pueden hacer combinaciones espaciales mediante la intersección de dos objetos, comúnmente puntos o polígonos.

Antes de empezar es recomendable vaciar los contenidos de la memoria

rm(list=ls())

Luego, haremos la instalación y cargaremos las librerias necesarias para desarrollar el trabajo

list.of.packages <- c("here", "tidyverse", "rgeos", "maptools", "raster", "sf",  "viridis", "rnaturalearth", "GSODR", "ggrepel", "cowplot")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
## Esta es una forma de verificar si la libreia se encuentra instalada
## ifelse(require(here)==T, "Cargado", "No cargado")
library(here)
## here() starts at C:/Users/laura/Desktop/Geomatica
library(tidyverse)
## -- Attaching packages ----------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2     v purrr   0.3.4
## v tibble  3.0.3     v dplyr   1.0.2
## v tidyr   1.1.2     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.0
## -- Conflicts -------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(rgeos)
## Loading required package: sp
## rgeos version: 0.5-5, (SVN revision 640)
##  GEOS runtime version: 3.8.0-CAPI-1.13.1 
##  Linking to sp version: 1.4-2 
##  Polygon checking: TRUE
library(maptools)
## Checking rgeos availability: TRUE
library(raster)
## 
## Attaching package: 'raster'
## The following object is masked from 'package:dplyr':
## 
##     select
## The following object is masked from 'package:tidyr':
## 
##     extract
library(sf)
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(viridis)
## Loading required package: viridisLite
library(rnaturalearth)
library(GSODR)
library(ggrepel)
library(cowplot)

Exploración de las estadísticas de la agricultura del departamento de Antioquia

Para empezar debemos descargar una base de datos de las Estadísticas Municipales Agropecuarias en formato .csv, para un mejor desarrollo del trabajo es recomendable editar los datos de tal manera que solo trabajemos con el departamento y columnas de interés; sin embargo, en este cuaderno trabajaremos con la base de datos completa y filtraremos los datos según el departamento que queremos analizar, en este caso Antioquia.

A continuación cargaremos el archivo con la base de datos completa

datos <- read_csv("C:/Users/laura/Desktop/Geomatica/Evaluaciones_Agropecuarias_Municipales_EVA.csv")
## 
## -- Column specification ----------------------------------------------------------
## cols(
##   `CÓD. 
## DEP.` = col_double(),
##   DEPARTAMENTO = col_character(),
##   `CÓD. MUN.` = col_double(),
##   MUNICIPIO = col_character(),
##   `GRUPO 
## DE CULTIVO` = col_character(),
##   `SUBGRUPO 
## DE CULTIVO` = col_character(),
##   CULTIVO = col_character(),
##   `DESAGREGACIÓN REGIONAL Y/O SISTEMA PRODUCTIVO` = col_character(),
##   AÑO = col_double(),
##   PERIODO = col_character(),
##   `Área Sembrada
## (ha)` = col_double(),
##   `Área Cosechada
## (ha)` = col_double(),
##   `Producción
## (t)` = col_double(),
##   `Rendimiento
## (t/ha)` = col_double(),
##   `ESTADO FISICO PRODUCCION` = col_character(),
##   `NOMBRE 
## CIENTIFICO` = col_character(),
##   `CICLO DE CULTIVO` = col_character()
## )

Ahora exploraremos algunos datos del archivo

head(datos)
## # A tibble: 6 x 17
##   `CÓD. \nDEP.` DEPARTAMENTO `CÓD. MUN.` MUNICIPIO `GRUPO \nDE CUL~
##           <dbl> <chr>              <dbl> <chr>     <chr>           
## 1            15 BOYACA             15114 BUSBANZA  HORTALIZAS      
## 2            25 CUNDINAMARCA       25754 SOACHA    HORTALIZAS      
## 3            25 CUNDINAMARCA       25214 COTA      HORTALIZAS      
## 4            54 NORTE DE SA~       54405 LOS PATI~ HORTALIZAS      
## 5            54 NORTE DE SA~       54518 PAMPLONA  HORTALIZAS      
## 6            68 SANTANDER          68377 LA BELLE~ HORTALIZAS      
## # ... with 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>
tail(datos)
## # A tibble: 6 x 17
##   `CÓD. \nDEP.` DEPARTAMENTO `CÓD. MUN.` MUNICIPIO `GRUPO \nDE CUL~
##           <dbl> <chr>              <dbl> <chr>     <chr>           
## 1            25 CUNDINAMARCA       25524 PANDI     HORTALIZAS      
## 2            25 CUNDINAMARCA       25436 MANTA     HORTALIZAS      
## 3            25 CUNDINAMARCA       25524 PANDI     HORTALIZAS      
## 4            25 CUNDINAMARCA       25436 MANTA     HORTALIZAS      
## 5            25 CUNDINAMARCA       25807 TIBIRITA  HORTALIZAS      
## 6            25 CUNDINAMARCA       25524 PANDI     HORTALIZAS      
## # ... with 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>

Podemos obeservar que la tabla contiene valores estadísticos de área sembrada, área cosechada y rendimiento para diferentes cultivos a nivel municipal, los cuales podemos ubicar en la columna subgrupo y cultivo, además de otros atributos como el estado físico de la producción o el ciclo del cultivo.

Como podemos ver los nombres de las columnas tienen caracteres que impiden su lectura, como tildes, entonces cambiaremos el nombre de las columnas mediante el siguiente código

names(datos) <-c("Cod", "Departamento", "Cod_municipio", "Municipio", 
                 "Grupo", "Subgrupo", "Cultivo", "Sistema","Year", "Periodo", "Area_sembrada", "Area_cosechada",
                 "Produccion", "Rendimiento", "Estado", "Nombre",
                 "Ciclo")
datos
## # A tibble: 206,068 x 17
##      Cod Departamento Cod_municipio Municipio Grupo Subgrupo Cultivo Sistema
##    <dbl> <chr>                <dbl> <chr>     <chr> <chr>    <chr>   <chr>  
##  1    15 BOYACA               15114 BUSBANZA  HORT~ ACELGA   ACELGA  ACELGA 
##  2    25 CUNDINAMARCA         25754 SOACHA    HORT~ ACELGA   ACELGA  ACELGA 
##  3    25 CUNDINAMARCA         25214 COTA      HORT~ ACELGA   ACELGA  ACELGA 
##  4    54 NORTE DE SA~         54405 LOS PATI~ HORT~ ACELGA   ACELGA  ACELGA 
##  5    54 NORTE DE SA~         54518 PAMPLONA  HORT~ ACELGA   ACELGA  ACELGA 
##  6    68 SANTANDER            68377 LA BELLE~ HORT~ ACELGA   ACELGA  ACELGA 
##  7    25 CUNDINAMARCA         25754 SOACHA    HORT~ ACELGA   ACELGA  ACELGA 
##  8    25 CUNDINAMARCA         25214 COTA      HORT~ ACELGA   ACELGA  ACELGA 
##  9    54 NORTE DE SA~         54518 PAMPLONA  HORT~ ACELGA   ACELGA  ACELGA 
## 10    68 SANTANDER            68377 LA BELLE~ HORT~ ACELGA   ACELGA  ACELGA 
## # ... with 206,058 more rows, and 9 more variables: Year <dbl>, Periodo <chr>,
## #   Area_sembrada <dbl>, Area_cosechada <dbl>, Produccion <dbl>,
## #   Rendimiento <dbl>, Estado <chr>, Nombre <chr>, Ciclo <chr>

Luego de explorar la tabla y conocer sus atributos filtraremos los datos según nuestro departamento de interés y exploraremos este nuevo objeto (este será el nuevo objeto con el que trabajaremos en lo que resta del documento)

datos %>%
  filter(Departamento == "ANTIOQUIA") -> Antioquia
Antioquia
## # A tibble: 18,759 x 17
##      Cod Departamento Cod_municipio Municipio Grupo Subgrupo Cultivo Sistema
##    <dbl> <chr>                <dbl> <chr>     <chr> <chr>    <chr>   <chr>  
##  1     5 ANTIOQUIA             5440 MARINILLA HORT~ ACELGA   ACELGA  ACELGA 
##  2     5 ANTIOQUIA             5440 MARINILLA HORT~ ACELGA   ACELGA  ACELGA 
##  3     5 ANTIOQUIA             5440 MARINILLA HORT~ ACELGA   ACELGA  ACELGA 
##  4     5 ANTIOQUIA             5440 MARINILLA HORT~ ACELGA   ACELGA  ACELGA 
##  5     5 ANTIOQUIA             5440 MARINILLA HORT~ ACELGA   ACELGA  ACELGA 
##  6     5 ANTIOQUIA             5475 MURINDO   TUBE~ MALANGA  MALANGA ACHIN  
##  7     5 ANTIOQUIA             5895 ZARAGOZA  PLAN~ PLANTAS~ ACHIOTE ACHIOT~
##  8     5 ANTIOQUIA             5264 ENTRERRI~ FRUT~ FRUTALE~ AGRAZ   AGRAZ  
##  9     5 ANTIOQUIA             5647 SAN ANDR~ FRUT~ FRUTALE~ AGRAZ   AGRAZ  
## 10     5 ANTIOQUIA             5686 SANTA RO~ FRUT~ FRUTALE~ AGRAZ   AGRAZ  
## # ... with 18,749 more rows, and 9 more variables: Year <dbl>, Periodo <chr>,
## #   Area_sembrada <dbl>, Area_cosechada <dbl>, Produccion <dbl>,
## #   Rendimiento <dbl>, Estado <chr>, Nombre <chr>, Ciclo <chr>
head(Antioquia)
## # A tibble: 6 x 17
##     Cod Departamento Cod_municipio Municipio Grupo Subgrupo Cultivo Sistema
##   <dbl> <chr>                <dbl> <chr>     <chr> <chr>    <chr>   <chr>  
## 1     5 ANTIOQUIA             5440 MARINILLA HORT~ ACELGA   ACELGA  ACELGA 
## 2     5 ANTIOQUIA             5440 MARINILLA HORT~ ACELGA   ACELGA  ACELGA 
## 3     5 ANTIOQUIA             5440 MARINILLA HORT~ ACELGA   ACELGA  ACELGA 
## 4     5 ANTIOQUIA             5440 MARINILLA HORT~ ACELGA   ACELGA  ACELGA 
## 5     5 ANTIOQUIA             5440 MARINILLA HORT~ ACELGA   ACELGA  ACELGA 
## 6     5 ANTIOQUIA             5475 MURINDO   TUBE~ MALANGA  MALANGA ACHIN  
## # ... with 9 more variables: Year <dbl>, Periodo <chr>, Area_sembrada <dbl>,
## #   Area_cosechada <dbl>, Produccion <dbl>, Rendimiento <dbl>, Estado <chr>,
## #   Nombre <chr>, Ciclo <chr>
tail(Antioquia)
## # A tibble: 6 x 17
##     Cod Departamento Cod_municipio Municipio Grupo Subgrupo Cultivo Sistema
##   <dbl> <chr>                <dbl> <chr>     <chr> <chr>    <chr>   <chr>  
## 1     5 ANTIOQUIA             5761 SOPETRAN  FRUT~ ZAPOTE   ZAPOTE  ZAPOTE 
## 2     5 ANTIOQUIA             5854 VALDIVIA  FRUT~ ZAPOTE   ZAPOTE  ZAPOTE 
## 3     5 ANTIOQUIA             5142 CARACOLI  FRUT~ ZAPOTE   ZAPOTE  ZAPOTE 
## 4     5 ANTIOQUIA             5761 SOPETRAN  FRUT~ ZAPOTE   ZAPOTE  ZAPOTE 
## 5     5 ANTIOQUIA             5854 VALDIVIA  FRUT~ ZAPOTE   ZAPOTE  ZAPOTE 
## 6     5 ANTIOQUIA             5142 CARACOLI  FRUT~ ZAPOTE   ZAPOTE  ZAPOTE 
## # ... with 9 more variables: Year <dbl>, Periodo <chr>, Area_sembrada <dbl>,
## #   Area_cosechada <dbl>, Produccion <dbl>, Rendimiento <dbl>, Estado <chr>,
## #   Nombre <chr>, Ciclo <chr>

Usaremos la biblioteca dplyr para explorar el archivo.

Ahora si podemos obtener el rendimiento de cada municipio según el grupo al que pertenece el cultivo

Antioquia %>%
  group_by(Municipio, Grupo) %>%
  summarise(rend_prom = mean(Rendimiento, na.rm = TRUE)) -> rend_resumen
## `summarise()` regrouping output by 'Municipio' (override with `.groups` argument)
head(rend_resumen)
## # A tibble: 6 x 3
## # Groups:   Municipio [1]
##   Municipio Grupo             rend_prom
##   <chr>     <chr>                 <dbl>
## 1 ABEJORRAL CEREALES               3.63
## 2 ABEJORRAL FIBRAS               NaN   
## 3 ABEJORRAL FLORES Y FOLLAJES     17.3 
## 4 ABEJORRAL FRUTALES              11.7 
## 5 ABEJORRAL HORTALIZAS           110   
## 6 ABEJORRAL LEGUMINOSAS            1.41

También podemos calcular el rendimiento promedio por Grupo en los municipios de Antioquia

Antioquia %>%
  group_by(Grupo) %>%
  summarise(rend_dep = mean(Rendimiento, na.rm = TRUE)) -> rend_antioquia
## `summarise()` ungrouping output (override with `.groups` argument)
rend_antioquia
## # A tibble: 11 x 2
##    Grupo                                            rend_dep
##    <chr>                                               <dbl>
##  1 CEREALES                                             1.87
##  2 FIBRAS                                               1.50
##  3 FLORES Y FOLLAJES                                    9.59
##  4 FORESTALES                                           1.06
##  5 FRUTALES                                            14.0 
##  6 HORTALIZAS                                          39.5 
##  7 LEGUMINOSAS                                          1.36
##  8 OLEAGINOSAS                                          2.86
##  9 OTROS PERMANENTES                                    2.01
## 10 PLANTAS AROMATICAS, CONDIMENTARIAS Y MEDICINALES     4.34
## 11 TUBERCULOS Y PLATANOS                               10.3

Podemos evidenciar que el mayor rendimiento promedio según el grupo de cultivo son las hortalizas con un valor de 39.48 Ton/ha, seguido de los frutales con 14.01 Ton/ha y tubérculos y plátanos con 10.26 Ton/ha.

Ahora, busquemos los municipios con mayor rendimiento para cada grupo de cultivos en 2018:

Antioquia %>% 
  filter(Year==2018) %>% 
  group_by(Grupo, Municipio) %>%
  summarize(max_rend = max(Rendimiento, na.rm = TRUE)) %>%
    slice(which.max(max_rend)) -> rend_max_18
## Warning in max(Rendimiento, na.rm = TRUE): ningun argumento finito para max;
## retornando -Inf

## Warning in max(Rendimiento, na.rm = TRUE): ningun argumento finito para max;
## retornando -Inf

## Warning in max(Rendimiento, na.rm = TRUE): ningun argumento finito para max;
## retornando -Inf

## Warning in max(Rendimiento, na.rm = TRUE): ningun argumento finito para max;
## retornando -Inf

## Warning in max(Rendimiento, na.rm = TRUE): ningun argumento finito para max;
## retornando -Inf

## Warning in max(Rendimiento, na.rm = TRUE): ningun argumento finito para max;
## retornando -Inf

## Warning in max(Rendimiento, na.rm = TRUE): ningun argumento finito para max;
## retornando -Inf

## Warning in max(Rendimiento, na.rm = TRUE): ningun argumento finito para max;
## retornando -Inf

## Warning in max(Rendimiento, na.rm = TRUE): ningun argumento finito para max;
## retornando -Inf

## Warning in max(Rendimiento, na.rm = TRUE): ningun argumento finito para max;
## retornando -Inf

## Warning in max(Rendimiento, na.rm = TRUE): ningun argumento finito para max;
## retornando -Inf

## Warning in max(Rendimiento, na.rm = TRUE): ningun argumento finito para max;
## retornando -Inf

## Warning in max(Rendimiento, na.rm = TRUE): ningun argumento finito para max;
## retornando -Inf
## `summarise()` regrouping output by 'Grupo' (override with `.groups` argument)
rend_max_18
## # A tibble: 11 x 3
## # Groups:   Grupo [11]
##    Grupo                                            Municipio   max_rend
##    <chr>                                            <chr>          <dbl>
##  1 CEREALES                                         LA UNION        33.6
##  2 FIBRAS                                           GOMEZ PLATA      2.6
##  3 FLORES Y FOLLAJES                                GUARNE          35  
##  4 FORESTALES                                       CACERES          2  
##  5 FRUTALES                                         NECOCLI         99  
##  6 HORTALIZAS                                       GUATAPE        192. 
##  7 LEGUMINOSAS                                      PEÑOL            9  
##  8 OLEAGINOSAS                                      DABEIBA          7  
##  9 OTROS PERMANENTES                                BRICEÑO         28  
## 10 PLANTAS AROMATICAS, CONDIMENTARIAS Y MEDICINALES RIONEGRO        15.2
## 11 TUBERCULOS Y PLATANOS                            URRAO           40.5

Observe que el municipio con mayor rendimiento para el año 2018 fue Guatapé con el cultivo de hortalizas y un rendimiento de 192 Ton/ha, seguido de Urrao con el cultivo de tubérculos y plátanos.

También podemos saber los municipios con mayor área cosechada en el 2018 para cada grupo de cultivos

Antioquia %>% 
  filter(Year==2018) %>% 
  group_by(Grupo, Municipio) %>%
  summarize(max_area_cosecha = max(Area_cosechada, na.rm = TRUE)) %>%
    slice(which.max(max_area_cosecha)) -> area_cosecha_max
## `summarise()` regrouping output by 'Grupo' (override with `.groups` argument)
area_cosecha_max
## # A tibble: 11 x 3
## # Groups:   Grupo [11]
##    Grupo                                       Municipio        max_area_cosecha
##    <chr>                                       <chr>                       <dbl>
##  1 CEREALES                                    NECOCLI                      3900
##  2 FIBRAS                                      URRAO                         157
##  3 FLORES Y FOLLAJES                           CARMEN DE VIBOR~              678
##  4 FORESTALES                                  TARAZA                        760
##  5 FRUTALES                                    TURBO                       10560
##  6 HORTALIZAS                                  CARMEN DE VIBOR~             1000
##  7 LEGUMINOSAS                                 SAN VICENTE                   911
##  8 OLEAGINOSAS                                 MUTATA                        700
##  9 OTROS PERMANENTES                           ANDES                        7648
## 10 PLANTAS AROMATICAS, CONDIMENTARIAS Y MEDIC~ RIONEGRO                       52
## 11 TUBERCULOS Y PLATANOS                       TURBO                        9441

Segun los datos filtrados podemos observar que el municipio con mayor área cosechada para el año 2018 fue Turbo con un valor de 10560 ha perteneciente al cultivo de frutales. Debido a sus caracteristicas geográficas, Turbo esta comprendido dentro del eje bananero de Antioquia, siendo este cultivo el principal rubro de exportación y de demanda laboral.

Luego de conocer esta información revisemos la producción de banano en el municipio de turbo para cada año registrado

Antioquia %>% 
  filter(Municipio=="TURBO" & Subgrupo=="BANANO") %>% 
  group_by(Year, Cultivo) ->  turbo_banano

turbo_banano
## # A tibble: 18 x 17
## # Groups:   Year, Cultivo [18]
##      Cod Departamento Cod_municipio Municipio Grupo Subgrupo Cultivo Sistema
##    <dbl> <chr>                <dbl> <chr>     <chr> <chr>    <chr>   <chr>  
##  1     5 ANTIOQUIA             5837 TURBO     FRUT~ BANANO   BANANO  BANANO~
##  2     5 ANTIOQUIA             5837 TURBO     FRUT~ BANANO   BANANO  BANANO~
##  3     5 ANTIOQUIA             5837 TURBO     FRUT~ BANANO   BANANO  BANANO~
##  4     5 ANTIOQUIA             5837 TURBO     FRUT~ BANANO   BANANO  BANANO~
##  5     5 ANTIOQUIA             5837 TURBO     FRUT~ BANANO   BANANO  BANANO~
##  6     5 ANTIOQUIA             5837 TURBO     FRUT~ BANANO   BANANO  BANANO~
##  7     5 ANTIOQUIA             5837 TURBO     FRUT~ BANANO   BANANO  BANANO~
##  8     5 ANTIOQUIA             5837 TURBO     FRUT~ BANANO   BANANO  BANANO~
##  9     5 ANTIOQUIA             5837 TURBO     FRUT~ BANANO   BANANO  BANANO~
## 10     5 ANTIOQUIA             5837 TURBO     FRUT~ BANANO   BANANO  BANANO~
## 11     5 ANTIOQUIA             5837 TURBO     FRUT~ BANANO   BANANO  BANANO~
## 12     5 ANTIOQUIA             5837 TURBO     FRUT~ BANANO   BANANO  BANANO~
## 13     5 ANTIOQUIA             5837 TURBO     FRUT~ BANANO   BANANI~ BANANO~
## 14     5 ANTIOQUIA             5837 TURBO     FRUT~ BANANO   BANANI~ BANANO~
## 15     5 ANTIOQUIA             5837 TURBO     FRUT~ BANANO   BANANI~ BANANO~
## 16     5 ANTIOQUIA             5837 TURBO     FRUT~ BANANO   BANANI~ BANANO~
## 17     5 ANTIOQUIA             5837 TURBO     FRUT~ BANANO   BANANI~ BANANO~
## 18     5 ANTIOQUIA             5837 TURBO     FRUT~ BANANO   BANANI~ BANANO~
## # ... with 9 more variables: Year <dbl>, Periodo <chr>, Area_sembrada <dbl>,
## #   Area_cosechada <dbl>, Produccion <dbl>, Rendimiento <dbl>, Estado <chr>,
## #   Nombre <chr>, Ciclo <chr>

Para visualizar mejor estos datos realicemos una exploración mediante un gráfico de barras de la producción de banano durante el periodo 2007 y 2018.

g <- ggplot(aes(x=Year, y=Produccion/1000), data = turbo_banano) + geom_bar(stat='identity') + labs(y='Producción de Banano [Ton x 1000]')
g + ggtitle("Evolucion de la producción de banano en Turbo entre el 2007 y 2018") + labs(caption= "Basado en datos de EMA (DANE, 2018)")

Ahora revisemos los cultivos del departamento de Antioquia con mayor área cosechada para el año 2018

Antioquia %>% 
  filter(Year==2018) %>% 
  group_by(Grupo) %>%
  summarize(sum_area_cosecha = sum(Area_cosechada, na.rm = TRUE)) %>%
     arrange(desc(sum_area_cosecha)) -> total_area_cosecha
## `summarise()` ungrouping output (override with `.groups` argument)
total_area_cosecha
## # A tibble: 11 x 2
##    Grupo                                            sum_area_cosecha
##    <chr>                                                       <dbl>
##  1 OTROS PERMANENTES                                          153313
##  2 TUBERCULOS Y PLATANOS                                       71233
##  3 FRUTALES                                                    66233
##  4 CEREALES                                                    32996
##  5 LEGUMINOSAS                                                  8071
##  6 HORTALIZAS                                                   4693
##  7 OLEAGINOSAS                                                  2289
##  8 FLORES Y FOLLAJES                                            1946
##  9 FORESTALES                                                   1769
## 10 FIBRAS                                                        762
## 11 PLANTAS AROMATICAS, CONDIMENTARIAS Y MEDICINALES              147

En el cuadro anterior obtenido se observa que el grupo de cultivo con mayor área cosechada corresponde al grupo denominado OTROS PERMANENTES con un área de 153.313 ha cosechadas. Para poder comprender mejor cual es el cultivo con mayor área cosechada perteneciente a este grupo nos podemos remitir a la información proporcionada por el DANE la cual nos indica que es el cultivo de café.

La anterior información también podemos ubicarla en los datos mediante la siguiente línea de código

Antioquia %>%
  filter(Grupo=="OTROS PERMANENTES" & Year==2018) %>%
  group_by(Cultivo) %>%
  summarize(sum_cosecha = sum(Area_cosechada, na.rm = TRUE)) %>%
     arrange(desc(sum_cosecha)) -> total_cosecha
## `summarise()` ungrouping output (override with `.groups` argument)
total_cosecha
## # A tibble: 3 x 2
##   Cultivo       sum_cosecha
##   <chr>               <dbl>
## 1 CAFE                98038
## 2 CAÑA PANELERA       37989
## 3 CACAO               17286

Podemos observar en el cuadro anterior que los cultivos de mayor área cosechada pertenecientes al grupo de cultivos permanentes son el café, caña panelera y cacao.

El cultivo de café ha sido por muchos años parte de la cultura y tradición del departamento de Antioquia, incluso es allí donde se ubica uno de los origenes de Juan Valdez Café. En este departamento gran parte de su población se dedica a cultivar este alimento con un total de 80.238 productores de los 550.000 que tiene el país; que se extienden en 2.685 veredas de 94 de los 125 municipios del departamento aportando a un 15% de la producción nacional.

Los sistemas productivos que predominan en la caficultura antioqueña son pequeñas parcelas y pequeños productores, pues sus áreas son en promedio de 1.55 hectáreas.

El café proveniente de este lugar, dada su diversidad geográfica, se caracteriza por ser una bebida suave con notas dulces y diversidad de perfiles y sabores (Federación Nacional de Cafeteros Colombia).

También podemos filtrar los datos de los municipios con mayor área cosechada para cada cultivo permanente en el año 2018

Antioquia %>% 
  filter(Year==2018 & Grupo=="OTROS PERMANENTES") %>% 
  group_by(Cultivo, Municipio) %>%
  summarize(max_area2 = max(Area_cosechada, na.rm = TRUE)) %>%
    slice(which.max(max_area2)) -> area_cosecha2
## `summarise()` regrouping output by 'Cultivo' (override with `.groups` argument)
area_cosecha2
## # A tibble: 3 x 3
## # Groups:   Cultivo [3]
##   Cultivo       Municipio max_area2
##   <chr>         <chr>         <dbl>
## 1 CACAO         TURBO          1761
## 2 CAFE          ANDES          7648
## 3 CAÑA PANELERA YOLOMBO        5220

Para visualizar mejor estos datos realicemos una exploración mediante un gráfico de barras de la superficie total cosechada por grupos de cultivos durante el año 2018 para el departamento de Antioquia. Allí en el gráfico podemos observar que el cultivo con mayor área es el denominado otros premanentes, seguido de tubérculos y plátanos.

total_area_cosecha$CROP <- abbreviate(total_area_cosecha$Grupo, 3)
g <- ggplot(aes(x=CROP, y=sum_area_cosecha), data = total_area_cosecha) + geom_bar(stat='identity') + labs(y='Área total cosechada [Ha]')
g+ ggtitle("Superficie total cosechada por grupos de cultivos en 2018 para Antioquia") + theme(plot.title = element_text(hjust = 0.5)) +
   labs(caption= "Basado en datos de EMA (DANE, 2018)")

Incorporación de las estadísticas agrícolas a los municipios

Para empezar se debe subir un archivo shapefile de los datos administrativos del departamento de interés, los cuales se pueden obtener de la base de datos del DANE.

Para este segmento de código emplearemos la librería sf

ant_munic <- sf::st_read("./05_ANTIOQUIA/ADMINISTRATIVO/MGN_MPIO_POLITICO.shp")
## Reading layer `MGN_MPIO_POLITICO' from data source `C:\Users\laura\Desktop\Geomatica\05_ANTIOQUIA\ADMINISTRATIVO\MGN_MPIO_POLITICO.shp' using driver `ESRI Shapefile'
## Simple feature collection with 125 features and 9 fields
## geometry type:  POLYGON
## dimension:      XY
## bbox:           xmin: -77.12783 ymin: 5.418558 xmax: -73.88128 ymax: 8.873974
## geographic CRS: WGS 84
ant_munic
## Simple feature collection with 125 features and 9 fields
## geometry type:  POLYGON
## dimension:      XY
## bbox:           xmin: -77.12783 ymin: 5.418558 xmax: -73.88128 ymax: 8.873974
## geographic CRS: WGS 84
## First 10 features:
##    DPTO_CCDGO MPIO_CCDGO     MPIO_CNMBR
## 1          05      05001       MEDELLÍN
## 2          05      05101 CIUDAD BOLÍVAR
## 3          05      05107        BRICEÑO
## 4          05      05113       BURITICÁ
## 5          05      05120        CÁCERES
## 6          05      05093        BETULIA
## 7          05      05091        BETANIA
## 8          05      05088          BELLO
## 9          05      05086        BELMIRA
## 10         05      05079        BARBOSA
##                                           MPIO_CRSLC MPIO_NAREA MPIO_NANO
## 1                                               1965   374.8280      2017
## 2                                               1869   260.4461      2017
## 3               Ordenanza 27 de Noviembre 26 de 1980   376.3468      2017
## 4                                               1812   355.2103      2017
## 5  Decreto departamental 160 del 16 de Marzo de 1903  1873.8033      2017
## 6  Decreto departamental 629 del 28 de Enero de 1884   262.3675      2017
## 7               Ordenanza 42 del 24 de Abril de 1920   180.5260      2017
## 8                Ordenanza 48 del 29 deAbril de 1913   147.7589      2017
## 9                                               1814   296.1532      2017
## 10                                              1812   205.6662      2017
##    DPTO_CNMBR Shape_Leng Shape_Area                       geometry
## 1   ANTIOQUIA  1.0327835 0.03060723 POLYGON ((-75.66974 6.37359...
## 2   ANTIOQUIA  0.7085039 0.02124224 POLYGON ((-76.04467 5.92774...
## 3   ANTIOQUIA  1.0044720 0.03078496 POLYGON ((-75.45818 7.22284...
## 4   ANTIOQUIA  0.9637233 0.02902757 POLYGON ((-75.90857 6.97378...
## 5   ANTIOQUIA  2.9333643 0.15350440 POLYGON ((-75.20358 7.95716...
## 6   ANTIOQUIA  0.8476756 0.02141352 POLYGON ((-76.00304 6.28171...
## 7   ANTIOQUIA  0.6923058 0.01472138 POLYGON ((-75.95474 5.79522...
## 8   ANTIOQUIA  0.6143227 0.01206804 POLYGON ((-75.58203 6.42510...
## 9   ANTIOQUIA  1.1730035 0.02420036 POLYGON ((-75.69252 6.75917...
## 10  ANTIOQUIA  0.7700180 0.01680390 POLYGON ((-75.32148 6.51265...

Luego de llamar el archivo note que los datos corresponden a un simple feature y que tienen un sistema de referencia de coordenadas geográficas WGS84.

Ahora podemos usar la función left_join para unir los municipios y las estadísticas agrícolas, para ello es importante asegurarnos que los archivos compartan atributos para lograr unirlos con éxito. En este caso el atributo de unión será el código municipal que en los datos estadísticos es denominado Cod_municipio y en el shapefile MPIO_CCDGO.

Antioquia %>% filter (Municipio =="MEDELLIN") ->  med_datos

med_datos
## # A tibble: 595 x 17
##      Cod Departamento Cod_municipio Municipio Grupo Subgrupo Cultivo Sistema
##    <dbl> <chr>                <dbl> <chr>     <chr> <chr>    <chr>   <chr>  
##  1     5 ANTIOQUIA             5001 MEDELLIN  FRUT~ AGUACATE AGUACA~ AGUACA~
##  2     5 ANTIOQUIA             5001 MEDELLIN  FRUT~ AGUACATE AGUACA~ AGUACA~
##  3     5 ANTIOQUIA             5001 MEDELLIN  FRUT~ AGUACATE AGUACA~ AGUACA~
##  4     5 ANTIOQUIA             5001 MEDELLIN  FRUT~ AGUACATE AGUACA~ AGUACA~
##  5     5 ANTIOQUIA             5001 MEDELLIN  FRUT~ AGUACATE AGUACA~ AGUACA~
##  6     5 ANTIOQUIA             5001 MEDELLIN  FRUT~ AGUACATE AGUACA~ AGUACA~
##  7     5 ANTIOQUIA             5001 MEDELLIN  FRUT~ AGUACATE AGUACA~ AGUACA~
##  8     5 ANTIOQUIA             5001 MEDELLIN  FRUT~ AGUACATE AGUACA~ AGUACA~
##  9     5 ANTIOQUIA             5001 MEDELLIN  FRUT~ AGUACATE AGUACA~ AGUACA~
## 10     5 ANTIOQUIA             5001 MEDELLIN  FRUT~ AGUACATE AGUACA~ AGUACA~
## # ... with 585 more rows, and 9 more variables: Year <dbl>, Periodo <chr>,
## #   Area_sembrada <dbl>, Area_cosechada <dbl>, Produccion <dbl>,
## #   Rendimiento <dbl>, Estado <chr>, Nombre <chr>, Ciclo <chr>
class(med_datos$Cod_municipio)
## [1] "numeric"

Para realizar la unión, debemos modificar el tipo de datos y el contenido del código que identifica a cada municipio. Es recomendable crear una copia de los datos estadísticos originales para no perder estos datos luego de cualquier cambio.

datos2 <- Antioquia
datos2$TEMP <-  as.character(datos2$Cod_municipio)
datos2$MPIO_CCDGO <- as.factor(paste(0, datos2$TEMP, sep=""))
head(datos2)
## # A tibble: 6 x 19
##     Cod Departamento Cod_municipio Municipio Grupo Subgrupo Cultivo Sistema
##   <dbl> <chr>                <dbl> <chr>     <chr> <chr>    <chr>   <chr>  
## 1     5 ANTIOQUIA             5440 MARINILLA HORT~ ACELGA   ACELGA  ACELGA 
## 2     5 ANTIOQUIA             5440 MARINILLA HORT~ ACELGA   ACELGA  ACELGA 
## 3     5 ANTIOQUIA             5440 MARINILLA HORT~ ACELGA   ACELGA  ACELGA 
## 4     5 ANTIOQUIA             5440 MARINILLA HORT~ ACELGA   ACELGA  ACELGA 
## 5     5 ANTIOQUIA             5440 MARINILLA HORT~ ACELGA   ACELGA  ACELGA 
## 6     5 ANTIOQUIA             5475 MURINDO   TUBE~ MALANGA  MALANGA ACHIN  
## # ... with 11 more variables: Year <dbl>, Periodo <chr>, Area_sembrada <dbl>,
## #   Area_cosechada <dbl>, Produccion <dbl>, Rendimiento <dbl>, Estado <chr>,
## #   Nombre <chr>, Ciclo <chr>, TEMP <chr>, MPIO_CCDGO <fct>

Luego de revisar las características del nuevo objeto, filtraremos un solo año y seleccionaremos solo dos atributos relevantes para el cultivo de café

datos2 %>% filter(Cultivo == "CAFE")  -> datos3
head(datos3)
## # A tibble: 6 x 19
##     Cod Departamento Cod_municipio Municipio Grupo Subgrupo Cultivo Sistema
##   <dbl> <chr>                <dbl> <chr>     <chr> <chr>    <chr>   <chr>  
## 1     5 ANTIOQUIA             5101 CIUDAD B~ OTRO~ CAFE     CAFE    CAFE   
## 2     5 ANTIOQUIA             5034 ANDES     OTRO~ CAFE     CAFE    CAFE   
## 3     5 ANTIOQUIA             5642 SALGAR    OTRO~ CAFE     CAFE    CAFE   
## 4     5 ANTIOQUIA             5209 CONCORDIA OTRO~ CAFE     CAFE    CAFE   
## 5     5 ANTIOQUIA             5091 BETANIA   OTRO~ CAFE     CAFE    CAFE   
## 6     5 ANTIOQUIA             5093 BETULIA   OTRO~ CAFE     CAFE    CAFE   
## # ... with 11 more variables: Year <dbl>, Periodo <chr>, Area_sembrada <dbl>,
## #   Area_cosechada <dbl>, Produccion <dbl>, Rendimiento <dbl>, Estado <chr>,
## #   Nombre <chr>, Ciclo <chr>, TEMP <chr>, MPIO_CCDGO <fct>
class(datos3)
## [1] "spec_tbl_df" "tbl_df"      "tbl"         "data.frame"
datos4 <- datos3 %>% dplyr::select(Municipio, MPIO_CCDGO, Year, Produccion, Rendimiento) 
datos4
## # A tibble: 1,099 x 5
##    Municipio      MPIO_CCDGO  Year Produccion Rendimiento
##    <chr>          <fct>      <dbl>      <dbl>       <dbl>
##  1 CIUDAD BOLIVAR 05101       2007       9935        1.17
##  2 ANDES          05034       2007      13574        1.6 
##  3 SALGAR         05642       2007       4720        1.12
##  4 CONCORDIA      05209       2007       6182        1.23
##  5 BETANIA        05091       2007       5482        1.01
##  6 BETULIA        05093       2007       4826        1.06
##  7 ABEJORRAL      05002       2007       2329        0.61
##  8 SONSON         05756       2007       3600        1.2 
##  9 ITUANGO        05361       2007       3110        1.08
## 10 NARIÑO         05483       2007       2643        1   
## # ... with 1,089 more rows
datos4 %>% 
  gather("Year", "Produccion", "Rendimiento" , key = variable, value = number)
## # A tibble: 3,297 x 4
##    Municipio      MPIO_CCDGO variable number
##    <chr>          <fct>      <chr>     <dbl>
##  1 CIUDAD BOLIVAR 05101      Year       2007
##  2 ANDES          05034      Year       2007
##  3 SALGAR         05642      Year       2007
##  4 CONCORDIA      05209      Year       2007
##  5 BETANIA        05091      Year       2007
##  6 BETULIA        05093      Year       2007
##  7 ABEJORRAL      05002      Year       2007
##  8 SONSON         05756      Year       2007
##  9 ITUANGO        05361      Year       2007
## 10 NARIÑO         05483      Year       2007
## # ... with 3,287 more rows
head(datos4)
## # A tibble: 6 x 5
##   Municipio      MPIO_CCDGO  Year Produccion Rendimiento
##   <chr>          <fct>      <dbl>      <dbl>       <dbl>
## 1 CIUDAD BOLIVAR 05101       2007       9935        1.17
## 2 ANDES          05034       2007      13574        1.6 
## 3 SALGAR         05642       2007       4720        1.12
## 4 CONCORDIA      05209       2007       6182        1.23
## 5 BETANIA        05091       2007       5482        1.01
## 6 BETULIA        05093       2007       4826        1.06

A continución se mostrará un fragmento de código que permite convertir la tabla de atributos de formato largo a formato ancho

datos4 %>% 
  group_by(MPIO_CCDGO) %>% 
  mutate(Visit = 1:n()) %>% 
  gather("Year", "Produccion", "Rendimiento", key = variable, value = number) %>% 
  unite(combi, variable, Visit) %>%
  spread(combi, number) -> datos5
head(datos5)
## # A tibble: 6 x 38
## # Groups:   MPIO_CCDGO [6]
##   Municipio MPIO_CCDGO Produccion_1 Produccion_10 Produccion_11 Produccion_12
##   <chr>     <fct>             <dbl>         <dbl>         <dbl>         <dbl>
## 1 ABEJORRAL 05002              2329          3352          5018          4718
## 2 ABRIAQUI  05004                81           114           182           193
## 3 ALEJANDR~ 05021               733           682           788           786
## 4 AMAGA     05030               570           643           822           791
## 5 AMALFI    05031              1439          1825          1194          1212
## 6 ANDES     05034             13574         10029          9463          9888
## # ... with 32 more variables: Produccion_2 <dbl>, Produccion_3 <dbl>,
## #   Produccion_4 <dbl>, Produccion_5 <dbl>, Produccion_6 <dbl>,
## #   Produccion_7 <dbl>, Produccion_8 <dbl>, Produccion_9 <dbl>,
## #   Rendimiento_1 <dbl>, Rendimiento_10 <dbl>, Rendimiento_11 <dbl>,
## #   Rendimiento_12 <dbl>, Rendimiento_2 <dbl>, Rendimiento_3 <dbl>,
## #   Rendimiento_4 <dbl>, Rendimiento_5 <dbl>, Rendimiento_6 <dbl>,
## #   Rendimiento_7 <dbl>, Rendimiento_8 <dbl>, Rendimiento_9 <dbl>,
## #   Year_1 <dbl>, Year_10 <dbl>, Year_11 <dbl>, Year_12 <dbl>, Year_2 <dbl>,
## #   Year_3 <dbl>, Year_4 <dbl>, Year_5 <dbl>, Year_6 <dbl>, Year_7 <dbl>,
## #   Year_8 <dbl>, Year_9 <dbl>
tail(datos5)
## # A tibble: 6 x 38
## # Groups:   MPIO_CCDGO [6]
##   Municipio MPIO_CCDGO Produccion_1 Produccion_10 Produccion_11 Produccion_12
##   <chr>     <fct>             <dbl>         <dbl>         <dbl>         <dbl>
## 1 VALPARAI~ 05856               734           545           497           515
## 2 VEGACHI   05858               619           383           222           216
## 3 VENECIA   05861               586           718           869           880
## 4 YALI      05885                64           314           172           154
## 5 YARUMAL   05887               350           309           341           332
## 6 YOLOMBO   05890              1360          1337          1168          1190
## # ... with 32 more variables: Produccion_2 <dbl>, Produccion_3 <dbl>,
## #   Produccion_4 <dbl>, Produccion_5 <dbl>, Produccion_6 <dbl>,
## #   Produccion_7 <dbl>, Produccion_8 <dbl>, Produccion_9 <dbl>,
## #   Rendimiento_1 <dbl>, Rendimiento_10 <dbl>, Rendimiento_11 <dbl>,
## #   Rendimiento_12 <dbl>, Rendimiento_2 <dbl>, Rendimiento_3 <dbl>,
## #   Rendimiento_4 <dbl>, Rendimiento_5 <dbl>, Rendimiento_6 <dbl>,
## #   Rendimiento_7 <dbl>, Rendimiento_8 <dbl>, Rendimiento_9 <dbl>,
## #   Year_1 <dbl>, Year_10 <dbl>, Year_11 <dbl>, Year_12 <dbl>, Year_2 <dbl>,
## #   Year_3 <dbl>, Year_4 <dbl>, Year_5 <dbl>, Year_6 <dbl>, Year_7 <dbl>,
## #   Year_8 <dbl>, Year_9 <dbl>

Haremos una copia nuevamente de la colección de características simples por si ocurre algún imprevisto

ant_munic2 <- ant_munic
ant_munic_stat = left_join(ant_munic2, datos5, by="MPIO_CCDGO")
summary(ant_munic_stat)
##   DPTO_CCDGO         MPIO_CCDGO         MPIO_CNMBR         MPIO_CRSLC       
##  Length:125         Length:125         Length:125         Length:125        
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##    MPIO_NAREA        MPIO_NANO     DPTO_CNMBR          Shape_Leng    
##  Min.   :  15.84   Min.   :2017   Length:125         Min.   :0.1730  
##  1st Qu.: 140.35   1st Qu.:2017   Class :character   1st Qu.:0.6143  
##  Median : 258.09   Median :2017   Mode  :character   Median :0.8907  
##  Mean   : 503.74   Mean   :2017                      Mean   :1.1800  
##  3rd Qu.: 535.18   3rd Qu.:2017                      3rd Qu.:1.4197  
##  Max.   :2959.36   Max.   :2017                      Max.   :6.6118  
##                                                                      
##    Shape_Area        Municipio          Produccion_1     Produccion_10  
##  Min.   :0.001293   Length:125         Min.   :    0.0   Min.   :   17  
##  1st Qu.:0.011454   Class :character   1st Qu.:  227.2   1st Qu.:  271  
##  Median :0.021059   Mode  :character   Median :  733.5   Median :  718  
##  Mean   :0.041079                      Mean   : 1282.8   Mean   : 1346  
##  3rd Qu.:0.043801                      3rd Qu.: 1371.2   3rd Qu.: 1607  
##  Max.   :0.238949                      Max.   :13574.0   Max.   :10029  
##                                        NA's   :31        NA's   :36     
##  Produccion_11     Produccion_12      Produccion_2      Produccion_3    
##  Min.   :   14.0   Min.   :   13.0   Min.   :    0.0   Min.   :   11.0  
##  1st Qu.:  300.2   1st Qu.:  295.0   1st Qu.:  262.8   1st Qu.:  203.8  
##  Median :  871.0   Median :  902.5   Median :  707.0   Median :  541.0  
##  Mean   : 1593.4   Mean   : 1610.4   Mean   : 1208.7   Mean   : 1104.5  
##  3rd Qu.: 1927.0   3rd Qu.: 1844.2   3rd Qu.: 1217.5   3rd Qu.: 1252.8  
##  Max.   :11249.0   Max.   :11439.0   Max.   :13574.0   Max.   :13594.0  
##  NA's   :37        NA's   :37        NA's   :31        NA's   :31       
##   Produccion_4      Produccion_5      Produccion_6     Produccion_7    
##  Min.   :   13.0   Min.   :   10.0   Min.   :   0.0   Min.   :   12.0  
##  1st Qu.:  238.2   1st Qu.:  224.0   1st Qu.: 193.5   1st Qu.:  179.5  
##  Median :  694.5   Median :  611.5   Median : 525.5   Median :  495.0  
##  Mean   : 1291.3   Mean   : 1228.0   Mean   : 976.6   Mean   : 1124.9  
##  3rd Qu.: 1410.8   3rd Qu.: 1295.2   3rd Qu.:1259.2   3rd Qu.: 1139.5  
##  Max.   :13437.0   Max.   :10344.0   Max.   :5943.0   Max.   :10080.0  
##  NA's   :31        NA's   :31        NA's   :31       NA's   :34       
##   Produccion_8      Produccion_9   Rendimiento_1    Rendimiento_10 
##  Min.   :   12.0   Min.   :   17   Min.   :0.4300   Min.   :0.620  
##  1st Qu.:  182.0   1st Qu.:  264   1st Qu.:0.8800   1st Qu.:1.030  
##  Median :  543.5   Median :  716   Median :1.0000   Median :1.080  
##  Mean   : 1237.3   Mean   : 1351   Mean   :0.9796   Mean   :1.087  
##  3rd Qu.: 1335.0   3rd Qu.: 1601   3rd Qu.:1.1200   3rd Qu.:1.120  
##  Max.   :10296.0   Max.   :10097   Max.   :1.6000   Max.   :1.830  
##  NA's   :35        NA's   :36      NA's   :32       NA's   :36     
##  Rendimiento_11  Rendimiento_12  Rendimiento_2    Rendimiento_3   
##  Min.   :0.660   Min.   :0.620   Min.   :0.3800   Min.   :0.3800  
##  1st Qu.:1.010   1st Qu.:1.030   1st Qu.:0.7800   1st Qu.:0.6350  
##  Median :1.260   Median :1.290   Median :0.9500   Median :0.8950  
##  Mean   :1.289   Mean   :1.316   Mean   :0.9231   Mean   :0.8534  
##  3rd Qu.:1.520   3rd Qu.:1.550   3rd Qu.:1.0900   3rd Qu.:1.0200  
##  Max.   :1.820   Max.   :1.870   Max.   :1.6000   Max.   :1.6000  
##  NA's   :37      NA's   :37      NA's   :32       NA's   :31      
##  Rendimiento_4   Rendimiento_5    Rendimiento_6    Rendimiento_7   
##  Min.   :0.250   Min.   :0.2500   Min.   :0.4000   Min.   :0.3800  
##  1st Qu.:0.800   1st Qu.:0.8025   1st Qu.:0.7500   1st Qu.:0.6300  
##  Median :1.000   Median :0.9600   Median :0.7500   Median :0.7500  
##  Mean   :1.004   Mean   :0.9805   Mean   :0.8625   Mean   :0.7929  
##  3rd Qu.:1.238   3rd Qu.:1.2000   3rd Qu.:1.0000   3rd Qu.:0.9400  
##  Max.   :1.600   Max.   :2.0000   Max.   :1.5000   Max.   :1.5000  
##  NA's   :31      NA's   :31       NA's   :32       NA's   :34      
##  Rendimiento_8    Rendimiento_9       Year_1        Year_10        Year_11    
##  Min.   :0.4100   Min.   :0.660   Min.   :2007   Min.   :2016   Min.   :2017  
##  1st Qu.:0.6800   1st Qu.:0.990   1st Qu.:2007   1st Qu.:2016   1st Qu.:2017  
##  Median :0.8100   Median :1.040   Median :2007   Median :2016   Median :2017  
##  Mean   :0.8461   Mean   :1.051   Mean   :2007   Mean   :2016   Mean   :2017  
##  3rd Qu.:1.0100   3rd Qu.:1.090   3rd Qu.:2007   3rd Qu.:2016   3rd Qu.:2017  
##  Max.   :1.4900   Max.   :1.770   Max.   :2013   Max.   :2018   Max.   :2017  
##  NA's   :35       NA's   :36      NA's   :31     NA's   :36     NA's   :37    
##     Year_12         Year_2         Year_3         Year_4         Year_5    
##  Min.   :2018   Min.   :2008   Min.   :2009   Min.   :2010   Min.   :2011  
##  1st Qu.:2018   1st Qu.:2008   1st Qu.:2009   1st Qu.:2010   1st Qu.:2011  
##  Median :2018   Median :2008   Median :2009   Median :2010   Median :2011  
##  Mean   :2018   Mean   :2008   Mean   :2009   Mean   :2010   Mean   :2011  
##  3rd Qu.:2018   3rd Qu.:2008   3rd Qu.:2009   3rd Qu.:2010   3rd Qu.:2011  
##  Max.   :2018   Max.   :2014   Max.   :2015   Max.   :2016   Max.   :2017  
##  NA's   :37     NA's   :31     NA's   :31     NA's   :31     NA's   :31    
##      Year_6         Year_7         Year_8         Year_9    
##  Min.   :2012   Min.   :2013   Min.   :2014   Min.   :2015  
##  1st Qu.:2012   1st Qu.:2013   1st Qu.:2014   1st Qu.:2015  
##  Median :2012   Median :2013   Median :2014   Median :2015  
##  Mean   :2012   Mean   :2013   Mean   :2014   Mean   :2015  
##  3rd Qu.:2012   3rd Qu.:2013   3rd Qu.:2014   3rd Qu.:2015  
##  Max.   :2018   Max.   :2018   Max.   :2018   Max.   :2017  
##  NA's   :31     NA's   :34     NA's   :35     NA's   :36    
##           geometry  
##  POLYGON      :125  
##  epsg:4326    :  0  
##  +proj=long...:  0  
##                     
##                     
##                     
## 

Gráfico

Intalemos algunas librerías que necesitaremos para realizar el gráfico

library(RColorBrewer)
library(leaflet)

A continuación graficaremos los municipios con su correspondiente producción de café para un año:

bins <- c(0, 250, 500, 1000, 2000, 5000, 10000, 15000)
pal <- colorBin("RdPu", domain = ant_munic_stat$Produccion_12, bins = bins)

  mapa <- leaflet(data = ant_munic_stat) %>%
  addTiles() %>%
  addPolygons(label = ~Produccion_12,
              popup = ~MPIO_CNMBR,
              fillColor = ~pal(Produccion_12),
              color = "#444444",
              weight = 1,
              smoothFactor = 0.5,
              opacity = 1.0,
              fillOpacity = 0.5,
              highlightOptions = highlightOptions(color = "white", weight = 2, bringToFront = TRUE)
              ) %>%
  addProviderTiles(providers$OpenStreetMap) %>%
  addLegend("bottomright", pal = pal, values = ~Produccion_12,
    title = "Coffee production in Antioquia [Ton] (2018)",
    opacity = 1
  )
mapa
sessionInfo()
## R version 4.0.2 (2020-06-22)
## Platform: i386-w64-mingw32/i386 (32-bit)
## Running under: Windows 10 x64 (build 18362)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=Spanish_Colombia.1252  LC_CTYPE=Spanish_Colombia.1252   
## [3] LC_MONETARY=Spanish_Colombia.1252 LC_NUMERIC=C                     
## [5] LC_TIME=Spanish_Colombia.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] leaflet_2.0.3       RColorBrewer_1.1-2  cowplot_1.1.0      
##  [4] ggrepel_0.8.2       GSODR_2.1.2         rnaturalearth_0.1.0
##  [7] viridis_0.5.1       viridisLite_0.3.0   sf_0.9-6           
## [10] raster_3.3-13       maptools_1.0-2      rgeos_0.5-5        
## [13] sp_1.4-4            forcats_0.5.0       stringr_1.4.0      
## [16] dplyr_1.0.2         purrr_0.3.4         readr_1.4.0        
## [19] tidyr_1.1.2         tibble_3.0.3        ggplot2_3.3.2      
## [22] tidyverse_1.3.0     here_0.1           
## 
## loaded via a namespace (and not attached):
##  [1] httr_1.4.2              jsonlite_1.7.1          modelr_0.1.8           
##  [4] assertthat_0.2.1        blob_1.2.1              cellranger_1.1.0       
##  [7] yaml_2.2.1              pillar_1.4.6            backports_1.1.10       
## [10] lattice_0.20-41         glue_1.4.2              digest_0.6.25          
## [13] rvest_0.3.6             leaflet.providers_1.9.0 colorspace_1.4-1       
## [16] htmltools_0.5.0         pkgconfig_2.0.3         broom_0.7.1            
## [19] haven_2.3.1             scales_1.1.1            farver_2.0.3           
## [22] generics_0.0.2          ellipsis_0.3.1          withr_2.3.0            
## [25] cli_2.0.2               magrittr_1.5            crayon_1.3.4           
## [28] readxl_1.3.1            evaluate_0.14           fs_1.5.0               
## [31] fansi_0.4.1             xml2_1.3.2              foreign_0.8-80         
## [34] class_7.3-17            tools_4.0.2             data.table_1.13.0      
## [37] hms_0.5.3               lifecycle_0.2.0         munsell_0.5.0          
## [40] reprex_0.3.0            compiler_4.0.2          e1071_1.7-3            
## [43] rlang_0.4.7             classInt_0.4-3          units_0.6-7            
## [46] grid_4.0.2              rstudioapi_0.11         htmlwidgets_1.5.2      
## [49] crosstalk_1.1.0.1       labeling_0.3            rmarkdown_2.4          
## [52] gtable_0.3.0            codetools_0.2-16        DBI_1.1.0              
## [55] R6_2.4.1                gridExtra_2.3           lubridate_1.7.9        
## [58] knitr_1.30              utf8_1.1.4              rprojroot_1.3-2        
## [61] KernSmooth_2.23-17      stringi_1.5.3           Rcpp_1.0.5             
## [64] vctrs_0.3.4             dbplyr_1.4.4            tidyselect_1.1.0       
## [67] xfun_0.18