“## My notebook”
This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
Según un articulo publicado en la pagina del Instituto Geográfico Agustín Codazzi (IGAC) llamado " Hasta en la seca Guajirala actividad agropecuaria está extramilitada", informa que a pesar de que el 14.9% del departamento cuenta con suelos aptos para el establecimiento de cultivos y ganadería , actualmente se hace uso del 20.5%.
El IGAC dice que en LA GUAJIRA actualmente el 20,5% cuenta con producción de cultivos de yuca, banano y frutas, en conbinación con ganado tanto vacuno como caprino; en municipios como Dibulla, San Juan del Cesar, Riohacha, Distracción, Maicao, Hato Nuevo, Albania, Barrancas, Fonseca, San Juan del Cesar, El Molino, Villanueva, La Jagua del Pilar, El Molino y Urumita.
rm(list=ls())
Intalación de Paquetes necesarios
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)
cargar librerias
library(here)
here() starts at C:/Users/familiar/Downloads/gb2/trabajos en R/guaji
library(tidyverse)
Registered S3 methods overwritten by 'dbplyr':
method from
print.tbl_lazy
print.tbl_sql
[37m-- [1mAttaching packages[22m --------------------------------------- tidyverse 1.3.0 --[39m
[37m[32mv[37m [34mggplot2[37m 3.3.0 [32mv[37m [34mpurrr [37m 0.3.3
[32mv[37m [34mtibble [37m 2.1.3 [32mv[37m [34mdplyr [37m 0.8.5
[32mv[37m [34mtidyr [37m 1.0.2 [32mv[37m [34mstringr[37m 1.4.0
[32mv[37m [34mreadr [37m 1.3.1 [32mv[37m [34mforcats[37m 0.5.0[39m
[37m-- [1mConflicts[22m ------------------------------------------ tidyverse_conflicts() --
[31mx[37m [34mdplyr[37m::[32mfilter()[37m masks [34mstats[37m::filter()
[31mx[37m [34mdplyr[37m::[32mlag()[37m masks [34mstats[37m::lag()[39m
library(rgeos)
Loading required package: sp
rgeos version: 0.5-2, (SVN revision 621)
GEOS runtime version: 3.6.1-CAPI-1.10.1
Linking to sp version: 1.4-1
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.6.1, GDAL 2.2.3, PROJ 4.9.3
library(viridis)
Loading required package: viridisLite
library(rnaturalearth)
library(GSODR)
Registered S3 method overwritten by 'data.table':
method from
print.data.table
library(ggrepel)
library(cowplot)
********************************************************
Note: As of version 1.0.0, cowplot does not change the
default ggplot2 theme anymore. To recover the previous
behavior, execute:
theme_set(theme_cowplot())
********************************************************
datos <- read.csv("C:/Users/familiar/Downloads/gb2/La guajira/Eval_Agro_Mun_La_Guajira_EVA (1).csv")
class(datos)
[1] "data.frame"
En la tabla siguiente podemos ver las primeras 6 lineas de toda la base de datos de la evaluación agraria de La Guajira , con la cual se va a trabajar en este cuaderno.
head(datos)
Se hace visualisar los últimos seis datos de toda la información suministrada por el GOV.CO Datos Abiertos, indica que se trabajaran con 3286 filas que estan compuestas por 17 columnas.
tail(datos)
Se indica en la siguiente tabla algunos rendimientos de los cultivos de la región , en la cual podemos destacar que se tiene los mayores rendimientos en los cultivos de frutales con 12.9 ton/ha , seguido por hortalizas con 9.3 ton/ha , cereales y fibras entre otros
datos %>%
group_by(MUNICIPIO,GRUPO.DE.CULTIVO) %>%
summarise(rend_prom = mean(Rendimiento.t.ha,na.rm = TRUE)) -> rend_resumen
### luego mostrará los primeros 6 datos de toda la tabla
head(rend_resumen)
Aquí podemos visualizar algunos grupos de cultivo con su rendimiento en el departamento de La Guajira
datos %>%
group_by(GRUPO.DE.CULTIVO) %>%
summarise(rend_dep = mean(Rendimiento.t.ha,na.rm = TRUE)) -> rend_guajira
rend_guajira
datos %>%
filter(AÑO==2018) %>%
group_by(GRUPO.DE.CULTIVO, MUNICIPIO) %>%
summarize(max_rend = max(Rendimiento.t.ha,na.rm = TRUE)) %>%
slice(which.max(max_rend)) -> rend_max_18
rend_max_18
En los siguientes datos se tiene información del grupo de cultivo por municipio con su área maxima cosechada
datos %>%
filter(AÑO==2018) %>%
group_by(GRUPO.DE.CULTIVO, MUNICIPIO) %>%
summarize(max_area_cosecha = max(A.rea.Cosechada.ha, na.rm = TRUE)) %>%
slice(which.max(max_area_cosecha)) -> area_cosecha_max
area_cosecha_max
Podemos verificar un cultivo y municipio en especial , para este caso tomaremos el Banano , en el municipio de Riohacha
datos %>%
filter(MUNICIPIO=="RIOHACHA" & SUBGRUPO.DE.CULTIVO=="BANANO") %>%
group_by(AÑO, CULTIVO) -> riohacha_banano
riohacha_banano
# we use the ggplot 2 library
g <- ggplot(aes(x=AÑO, y=Produccion.ton/1000), data = riohacha_banano) + geom_bar(stat='identity') + labs(y='Produccion.ton[Ton x 1000]')
Se realiza un grafico en donde nos muetra la evolución del banano en Riohacha , y podemos observar que ha tenido un incremento en su producción desde el 2007 hasta el 2018, pasando del 2007 de menos de 5000 toneladas a mas 80.000 ton en el 2018
g + ggtitle("Evolucion de produccion Banano en Riohacha de 2007 a 2018") + labs(caption= "Based on EMA data (DANE, 2018)")
datos %>%
filter(AÑO==2018) %>%
group_by(GRUPO.DE.CULTIVO) %>%
summarize(sum_area_cosecha = sum(A.rea.Cosechada.ha, na.rm = TRUE)) %>%
arrange(desc(sum_area_cosecha)) -> total_area_cosecha
total_area_cosecha
En la anterior tabla se calculó cada grupo de cultivo la suma del área de su cosecha , donde se destaca los cereales
datos %>%
filter(GRUPO.DE.CULTIVO=="OTROS PERMANENTES" & AÑO==2018) %>%
group_by(CULTIVO) %>%
summarize(sum_cosecha = sum(A.rea.Cosechada.ha, na.rm = TRUE)) %>%
arrange(desc(sum_cosecha)) -> total_cosecha
total_cosecha
Aquí se muestran otros datos de otros cultivos permanentes , encontrando primero al Café con la mayor área cosechada
datos %>%
filter(AÑO==2018 & GRUPO.DE.CULTIVO=="OTROS PERMANENTES") %>%
group_by(CULTIVO, MUNICIPIO) %>%
summarize(max_area2 = max(A.rea.Cosechada.ha, na.rm = TRUE)) %>%
slice(which.max(max_area2)) -> area_cosecha2
area_cosecha2
total_area_cosecha$CULTIVO <- abbreviate(total_area_cosecha$GRUPO.DE.CULTIVO, 3)
# we use the ggplot 2 library
g <- ggplot(aes(x=CULTIVO, y=sum_area_cosecha), data = total_area_cosecha) + geom_bar(stat='identity') + labs(y='Total Harvested Area [Ha]')
Basado en la información seleccionada se realiza un grafico donde se muestra el área cosechada por grupo de cultivo en el 2018 para La Guajira, donde la mayor área coschada es para los cereales.
g+ ggtitle("Total area cosechada por grupo de cultivo en 2018 for La Guajira") + theme(plot.title = element_text(hjust = 0.5)) +
labs(caption= "Based on EMA data (DANE, 2018)")
library(sf)
ant_munic <- sf::st_read("C:/Users/familiar/Downloads/gb2/La guajira/44_LA_GUAJIRA/ADMINISTRATIVO/MGN_MPIO_POLITICO.shp")
Reading layer `MGN_MPIO_POLITICO' from data source `C:\Users\familiar\Downloads\gb2\La guajira\44_LA_GUAJIRA\ADMINISTRATIVO\MGN_MPIO_POLITICO.shp' using driver `ESRI Shapefile'
Simple feature collection with 15 features and 9 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -73.66494 ymin: 10.39676 xmax: -71.11296 ymax: 12.45944
epsg (SRID): 4326
proj4string: +proj=longlat +datum=WGS84 +no_defs
ant_munic
Simple feature collection with 15 features and 9 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -73.66494 ymin: 10.39676 xmax: -71.11296 ymax: 12.45944
epsg (SRID): 4326
proj4string: +proj=longlat +datum=WGS84 +no_defs
First 10 features:
DPTO_CCDGO MPIO_CCDGO MPIO_CNMBR MPIO_CRSLC
1 44 44078 BARRANCAS 1935
2 44 44098 DISTRACCIÓN Ordenanza 41 de Noviembre 30 de 1995
3 44 44110 EL MOLINO Ordenanza015 del 29 de Noviembre de 1989
4 44 44279 FONSECA 1954
5 44 44378 HATONUEVO Ordenanza 57 de Noviembre 9 de 1994
6 44 44420 LA JAGUA DEL PILAR Decreto presidencial 609 del 26 de Marzo de 1996 y ratificad
7 44 44855 URUMITA Ordenanza 36 de Diciembre 20 de 1983
8 44 44874 VILLANUEVA 1888
9 44 44001 RIOHACHA 1954
10 44 44035 ALBANIA Ordenanza 001 del 27 de Marzo del 2000
MPIO_NAREA MPIO_NANO DPTO_CNMBR Shape_Leng Shape_Area geometry
1 800.9418 2017 LA GUAJIRA 1.4953574 0.06621447 MULTIPOLYGON (((-72.59885 1...
2 231.6880 2017 LA GUAJIRA 0.9018563 0.01916877 MULTIPOLYGON (((-72.89246 1...
3 242.1848 2017 LA GUAJIRA 0.7100496 0.02000174 MULTIPOLYGON (((-72.96901 1...
4 473.7073 2017 LA GUAJIRA 1.3186028 0.03912942 MULTIPOLYGON (((-72.91056 1...
5 214.6399 2017 LA GUAJIRA 1.1453524 0.01775162 MULTIPOLYGON (((-72.6568 11...
6 179.5909 2017 LA GUAJIRA 0.9805011 0.01482556 MULTIPOLYGON (((-73.08581 1...
7 246.2746 2017 LA GUAJIRA 1.0506924 0.02033173 MULTIPOLYGON (((-73.00927 1...
8 260.0959 2017 LA GUAJIRA 0.8830655 0.02147866 MULTIPOLYGON (((-72.9918 10...
9 3088.7157 2017 LA GUAJIRA 3.0307344 0.25561378 MULTIPOLYGON (((-72.89025 1...
10 546.0266 2017 LA GUAJIRA 1.4854163 0.04517060 MULTIPOLYGON (((-72.52248 1...
datos %>% filter (MUNICIPIO =="RIOHACHA") -> med_datos
med_datos
class(med_datos$C0D.MUN.)
[1] "integer"
datos2 <- datos
datos2$TEMP <- as.character(datos2$C0D.MUN.)
datos2$MPIO_CCDGO <- as.factor(paste(datos2$TEMP, sep=""))
head(datos2)
datos2 %>% filter(CULTIVO == "CAFE") -> datos3
datos3
head(datos3)
class(datos3)
[1] "data.frame"
library(dplyr)
datos4 <- datos3 %>% dplyr::select(MUNICIPIO, AÑO, Produccion.ton, Rendimiento.t.ha,MPIO_CCDGO)
datos4
datos4 %>%
gather("AÑO", "Produccion.ton", "Rendimiento.t.ha", key = variable, value = numeric)
datos4
head(datos4)
datos4 %>%
group_by(MPIO_CCDGO) %>%
mutate(Visit = 1:n()) %>%
gather("AÑO","Produccion.ton","Rendimiento.t.ha", key = variable, value = numeric) %>%
unite(combi, variable, Visit) %>%
spread(combi, numeric) -> datos5
datos5
head(datos5)
tail(datos5)
class(datos5)
[1] "grouped_df" "tbl_df" "tbl" "data.frame"
ant_munic2 <- ant_munic
ant_munic2
Simple feature collection with 15 features and 9 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -73.66494 ymin: 10.39676 xmax: -71.11296 ymax: 12.45944
epsg (SRID): 4326
proj4string: +proj=longlat +datum=WGS84 +no_defs
First 10 features:
DPTO_CCDGO MPIO_CCDGO MPIO_CNMBR MPIO_CRSLC
1 44 44078 BARRANCAS 1935
2 44 44098 DISTRACCIÓN Ordenanza 41 de Noviembre 30 de 1995
3 44 44110 EL MOLINO Ordenanza015 del 29 de Noviembre de 1989
4 44 44279 FONSECA 1954
5 44 44378 HATONUEVO Ordenanza 57 de Noviembre 9 de 1994
6 44 44420 LA JAGUA DEL PILAR Decreto presidencial 609 del 26 de Marzo de 1996 y ratificad
7 44 44855 URUMITA Ordenanza 36 de Diciembre 20 de 1983
8 44 44874 VILLANUEVA 1888
9 44 44001 RIOHACHA 1954
10 44 44035 ALBANIA Ordenanza 001 del 27 de Marzo del 2000
MPIO_NAREA MPIO_NANO DPTO_CNMBR Shape_Leng Shape_Area geometry
1 800.9418 2017 LA GUAJIRA 1.4953574 0.06621447 MULTIPOLYGON (((-72.59885 1...
2 231.6880 2017 LA GUAJIRA 0.9018563 0.01916877 MULTIPOLYGON (((-72.89246 1...
3 242.1848 2017 LA GUAJIRA 0.7100496 0.02000174 MULTIPOLYGON (((-72.96901 1...
4 473.7073 2017 LA GUAJIRA 1.3186028 0.03912942 MULTIPOLYGON (((-72.91056 1...
5 214.6399 2017 LA GUAJIRA 1.1453524 0.01775162 MULTIPOLYGON (((-72.6568 11...
6 179.5909 2017 LA GUAJIRA 0.9805011 0.01482556 MULTIPOLYGON (((-73.08581 1...
7 246.2746 2017 LA GUAJIRA 1.0506924 0.02033173 MULTIPOLYGON (((-73.00927 1...
8 260.0959 2017 LA GUAJIRA 0.8830655 0.02147866 MULTIPOLYGON (((-72.9918 10...
9 3088.7157 2017 LA GUAJIRA 3.0307344 0.25561378 MULTIPOLYGON (((-72.89025 1...
10 546.0266 2017 LA GUAJIRA 1.4854163 0.04517060 MULTIPOLYGON (((-72.52248 1...
ant_munic_stat = left_join(ant_munic,datos5, by = "MPIO_CCDGO")
ant_munic_stat
Simple feature collection with 15 features and 46 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -73.66494 ymin: 10.39676 xmax: -71.11296 ymax: 12.45944
epsg (SRID): 4326
proj4string: +proj=longlat +datum=WGS84 +no_defs
First 10 features:
DPTO_CCDGO MPIO_CCDGO MPIO_CNMBR MPIO_CRSLC
1 44 44078 BARRANCAS 1935
2 44 44098 DISTRACCIÓN Ordenanza 41 de Noviembre 30 de 1995
3 44 44110 EL MOLINO Ordenanza015 del 29 de Noviembre de 1989
4 44 44279 FONSECA 1954
5 44 44378 HATONUEVO Ordenanza 57 de Noviembre 9 de 1994
6 44 44420 LA JAGUA DEL PILAR Decreto presidencial 609 del 26 de Marzo de 1996 y ratificad
7 44 44855 URUMITA Ordenanza 36 de Diciembre 20 de 1983
8 44 44874 VILLANUEVA 1888
9 44 44001 RIOHACHA 1954
10 44 44035 ALBANIA Ordenanza 001 del 27 de Marzo del 2000
MPIO_NAREA MPIO_NANO DPTO_CNMBR Shape_Leng Shape_Area MUNICIPIO AÑO_1 AÑO_10 AÑO_11 AÑO_12
1 800.9418 2017 LA GUAJIRA 1.4953574 0.06621447 BARRANCAS 2007 2016 2017 2018
2 231.6880 2017 LA GUAJIRA 0.9018563 0.01916877 DISTRACCION 2007 NA NA NA
3 242.1848 2017 LA GUAJIRA 0.7100496 0.02000174 EL MOLINO 2007 2016 2017 2018
4 473.7073 2017 LA GUAJIRA 1.3186028 0.03912942 FONSECA 2007 2016 2017 2018
5 214.6399 2017 LA GUAJIRA 1.1453524 0.01775162 HATO NUEVO 2007 2016 2017 2018
6 179.5909 2017 LA GUAJIRA 0.9805011 0.01482556 LA JAGUA DEL PILAR 2007 2016 2017 2018
7 246.2746 2017 LA GUAJIRA 1.0506924 0.02033173 URUMITA 2007 2016 2017 2018
8 260.0959 2017 LA GUAJIRA 0.8830655 0.02147866 VILLANUEVA 2007 2016 2017 2018
9 3088.7157 2017 LA GUAJIRA 3.0307344 0.25561378 RIOHACHA 2007 2016 2017 2018
10 546.0266 2017 LA GUAJIRA 1.4854163 0.04517060 <NA> NA NA NA NA
AÑO_2 AÑO_3 AÑO_4 AÑO_5 AÑO_6 AÑO_7 AÑO_8 AÑO_9 Produccion.ton_1 Produccion.ton_10 Produccion.ton_11
1 2008 2009 2010 2011 2012 2013 2014 2015 421 582 418
2 2008 NA NA NA NA NA NA NA 15 NA NA
3 2008 2009 2010 2011 2012 2013 2014 2015 219 251 246
4 2008 2009 2010 2011 2012 2013 2014 2015 171 297 190
5 2008 2009 2010 2011 2012 2013 2014 2015 171 109 75
6 2008 2009 2010 2011 2012 2013 2014 2015 81 517 395
7 2008 2009 2010 2011 2012 2013 2014 2015 963 929 827
8 2008 2009 2010 2011 2012 2013 2014 2015 348 841 723
9 2008 2009 2010 2011 2012 2013 2014 2015 132 297 222
10 NA NA NA NA NA NA NA NA NA NA NA
Produccion.ton_12 Produccion.ton_2 Produccion.ton_3 Produccion.ton_4 Produccion.ton_5 Produccion.ton_6
1 390 431 340 258 215 351
2 NA 21 NA NA NA NA
3 232 192 217 144 120 275
4 207 142 170 211 146 245
5 74 63 47 64 41 67
6 344 143 107 157 126 277
7 504 493 425 636 500 1009
8 602 370 490 320 439 665
9 222 185 215 240 159 306
10 NA NA NA NA NA NA
Produccion.ton_7 Produccion.ton_8 Produccion.ton_9 Rendimiento.t.ha_1 Rendimiento.t.ha_10
1 358 464 594 1 1
2 NA NA NA 1 NA
3 299 323 251 1 1
4 231 264 280 1 1
5 63 66 106 2 1
6 334 405 506 1 1
7 820 909 934 1 1
8 672 734 826 1 1
9 299 311 295 1 1
10 NA NA NA NA NA
Rendimiento.t.ha_11 Rendimiento.t.ha_12 Rendimiento.t.ha_2 Rendimiento.t.ha_3 Rendimiento.t.ha_4
1 1 1 1 1 1
2 NA NA 1 NA NA
3 1 1 1 1 1
4 1 1 0 1 1
5 1 1 1 1 1
6 1 1 1 1 1
7 1 1 0 0 1
8 1 1 1 1 1
9 1 1 1 1 1
10 NA NA NA NA NA
Rendimiento.t.ha_5 Rendimiento.t.ha_6 Rendimiento.t.ha_7 Rendimiento.t.ha_8 Rendimiento.t.ha_9
1 1 1 1 1 1
2 NA NA NA NA NA
3 1 1 1 1 1
4 1 1 1 1 1
5 0 1 1 1 1
6 0 1 1 1 1
7 1 1 1 1 1
8 1 1 1 1 1
9 0 1 1 1 1
10 NA NA NA NA NA
geometry
1 MULTIPOLYGON (((-72.59885 1...
2 MULTIPOLYGON (((-72.89246 1...
3 MULTIPOLYGON (((-72.96901 1...
4 MULTIPOLYGON (((-72.91056 1...
5 MULTIPOLYGON (((-72.6568 11...
6 MULTIPOLYGON (((-73.08581 1...
7 MULTIPOLYGON (((-73.00927 1...
8 MULTIPOLYGON (((-72.9918 10...
9 MULTIPOLYGON (((-72.89025 1...
10 MULTIPOLYGON (((-72.52248 1...
summary(ant_munic_stat)
DPTO_CCDGO MPIO_CCDGO MPIO_CNMBR
44:15 Length:15 ALBANIA :1
Class :character BARRANCAS :1
Mode :character DIBULLA :1
DISTRACCIÓN:1
EL MOLINO :1
FONSECA :1
(Other) :9
MPIO_CRSLC MPIO_NAREA MPIO_NANO
1954 :4 Min. : 179.6 Min. :2017
1888 :1 1st Qu.: 244.2 1st Qu.:2017
1935 :1 Median : 546.0 Median :2017
1956 :1 Mean :1374.8 Mean :2017
Decreto presidencial 609 del 26 de Marzo de 1996 y ratificad:1 3rd Qu.:1684.8 3rd Qu.:2017
Ordenanza 001 del 27 de Marzo del 2000 :1 Max. :7886.1 Max. :2017
(Other) :6
DPTO_CNMBR Shape_Leng Shape_Area MUNICIPIO AÑO_1 AÑO_10
LA GUAJIRA:15 Min. :0.710 Min. :0.01483 BARRANCAS :1 Min. :2007 Min. :2016
1st Qu.:1.016 1st Qu.:0.02017 DIBULLA :1 1st Qu.:2007 1st Qu.:2016
Median :1.485 Median :0.04517 DISTRACCION:1 Median :2007 Median :2016
Mean :1.897 Mean :0.11381 EL MOLINO :1 Mean :2007 Mean :2016
3rd Qu.:2.288 3rd Qu.:0.13948 FONSECA :1 3rd Qu.:2007 3rd Qu.:2016
Max. :6.113 Max. :0.65355 (Other) :6 Max. :2007 Max. :2016
NA's :4 NA's :4 NA's :5
AÑO_11 AÑO_12 AÑO_2 AÑO_3 AÑO_4 AÑO_5 AÑO_6
Min. :2017 Min. :2018 Min. :2008 Min. :2009 Min. :2010 Min. :2011 Min. :2012
1st Qu.:2017 1st Qu.:2018 1st Qu.:2008 1st Qu.:2009 1st Qu.:2010 1st Qu.:2011 1st Qu.:2012
Median :2017 Median :2018 Median :2008 Median :2009 Median :2010 Median :2011 Median :2012
Mean :2017 Mean :2018 Mean :2008 Mean :2009 Mean :2010 Mean :2011 Mean :2012
3rd Qu.:2017 3rd Qu.:2018 3rd Qu.:2008 3rd Qu.:2009 3rd Qu.:2010 3rd Qu.:2011 3rd Qu.:2012
Max. :2017 Max. :2018 Max. :2008 Max. :2009 Max. :2010 Max. :2011 Max. :2012
NA's :5 NA's :5 NA's :4 NA's :5 NA's :5 NA's :5 NA's :5
AÑO_7 AÑO_8 AÑO_9 Produccion.ton_1 Produccion.ton_10 Produccion.ton_11
Min. :2013 Min. :2014 Min. :2015 Min. : 15 Min. :109.0 Min. : 75.0
1st Qu.:2013 1st Qu.:2014 1st Qu.:2015 1st Qu.:150 1st Qu.:262.5 1st Qu.:198.0
Median :2013 Median :2014 Median :2015 Median :171 Median :321.5 Median :274.5
Mean :2013 Mean :2014 Mean :2015 Mean :269 Mean :438.9 Mean :351.6
3rd Qu.:2013 3rd Qu.:2014 3rd Qu.:2015 3rd Qu.:309 3rd Qu.:565.8 3rd Qu.:412.2
Max. :2013 Max. :2014 Max. :2015 Max. :963 Max. :929.0 Max. :827.0
NA's :5 NA's :5 NA's :5 NA's :4 NA's :5 NA's :5
Produccion.ton_12 Produccion.ton_2 Produccion.ton_3 Produccion.ton_4 Produccion.ton_5 Produccion.ton_6
Min. : 74.0 Min. : 21.0 Min. : 47.0 Min. : 64.0 Min. : 30.0 Min. : 27.0
1st Qu.:210.8 1st Qu.:125.5 1st Qu.:164.2 1st Qu.:159.0 1st Qu.:121.5 1st Qu.: 221.0
Median :264.5 Median :180.0 Median :192.5 Median :204.5 Median :152.0 Median : 276.0
Mean :299.1 Mean :211.7 Mean :234.2 Mean :239.3 Mean :193.4 Mean : 343.5
3rd Qu.:378.5 3rd Qu.:281.0 3rd Qu.:309.2 3rd Qu.:253.5 3rd Qu.:201.0 3rd Qu.: 339.8
Max. :602.0 Max. :493.0 Max. :490.0 Max. :636.0 Max. :500.0 Max. :1009.0
NA's :5 NA's :4 NA's :5 NA's :5 NA's :5 NA's :5
Produccion.ton_7 Produccion.ton_8 Produccion.ton_9 Rendimiento.t.ha_1 Rendimiento.t.ha_10
Min. : 63.0 Min. : 66.0 Min. :106.0 Min. :1.000 Min. :1
1st Qu.:241.8 1st Qu.:273.0 1st Qu.:258.2 1st Qu.:1.000 1st Qu.:1
Median :299.0 Median :317.0 Median :306.5 Median :1.000 Median :1
Mean :344.8 Mean :392.4 Mean :431.9 Mean :1.091 Mean :1
3rd Qu.:352.0 3rd Qu.:449.2 3rd Qu.:572.0 3rd Qu.:1.000 3rd Qu.:1
Max. :820.0 Max. :909.0 Max. :934.0 Max. :2.000 Max. :1
NA's :5 NA's :5 NA's :5 NA's :4 NA's :5
Rendimiento.t.ha_11 Rendimiento.t.ha_12 Rendimiento.t.ha_2 Rendimiento.t.ha_3 Rendimiento.t.ha_4
Min. :1 Min. :1 Min. :0.0000 Min. :0.0 Min. :1
1st Qu.:1 1st Qu.:1 1st Qu.:1.0000 1st Qu.:1.0 1st Qu.:1
Median :1 Median :1 Median :1.0000 Median :1.0 Median :1
Mean :1 Mean :1 Mean :0.8182 Mean :0.9 Mean :1
3rd Qu.:1 3rd Qu.:1 3rd Qu.:1.0000 3rd Qu.:1.0 3rd Qu.:1
Max. :1 Max. :1 Max. :1.0000 Max. :1.0 Max. :1
NA's :5 NA's :5 NA's :4 NA's :5 NA's :5
Rendimiento.t.ha_5 Rendimiento.t.ha_6 Rendimiento.t.ha_7 Rendimiento.t.ha_8 Rendimiento.t.ha_9
Min. :0.0 Min. :1 Min. :1 Min. :1 Min. :1
1st Qu.:0.0 1st Qu.:1 1st Qu.:1 1st Qu.:1 1st Qu.:1
Median :1.0 Median :1 Median :1 Median :1 Median :1
Mean :0.6 Mean :1 Mean :1 Mean :1 Mean :1
3rd Qu.:1.0 3rd Qu.:1 3rd Qu.:1 3rd Qu.:1 3rd Qu.:1
Max. :1.0 Max. :1 Max. :1 Max. :1 Max. :1
NA's :5 NA's :5 NA's :5 NA's :5 NA's :5
geometry
MULTIPOLYGON :15
epsg:4326 : 0
+proj=long...: 0
#instalar paquete ("RColorBrewer")
library(RColorBrewer)
library(leaflet)
bins <- c(0, 25, 50, 100, 200, 400, 8000, 1200)
pal <- colorBin("YlOrRd", domain = ant_munic_stat$ Produccion.ton_12, bins = bins)
mapa <- leaflet(data = ant_munic_stat) %>%
addTiles() %>%
addPolygons(label = ~ Produccion.ton_12,
popup = ~MPIO_CNMBR,
fillColor = ~pal( Produccion.ton_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.ton_12,
title = "Producción de café en LA Guajira [Ton] (2018)",
opacity = 1
)
mapa
sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)
Matrix products: default
Random number generation:
RNG: Mersenne-Twister
Normal: Inversion
Sample: Rounding
locale:
[1] LC_COLLATE=Spanish_Latin America.1252 LC_CTYPE=Spanish_Latin America.1252
[3] LC_MONETARY=Spanish_Latin America.1252 LC_NUMERIC=C
[5] LC_TIME=Spanish_Latin America.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.0.0 ggrepel_0.8.2 GSODR_2.0.1
[6] rnaturalearth_0.1.0 viridis_0.5.1 viridisLite_0.3.0 sf_0.8-1 raster_3.0-12
[11] maptools_0.9-9 rgeos_0.5-2 sp_1.4-1 forcats_0.5.0 stringr_1.4.0
[16] dplyr_0.8.5 purrr_0.3.3 readr_1.3.1 tidyr_1.0.2 tibble_2.1.3
[21] ggplot2_3.3.0 tidyverse_1.3.0 here_0.1
loaded via a namespace (and not attached):
[1] httr_1.4.1 jsonlite_1.6.1 modelr_0.1.6 assertthat_0.2.1
[5] cellranger_1.1.0 yaml_2.2.1 pillar_1.4.3 backports_1.1.5
[9] lattice_0.20-40 glue_1.3.2 digest_0.6.25 rvest_0.3.5
[13] leaflet.providers_1.9.0 colorspace_1.4-1 htmltools_0.4.0 pkgconfig_2.0.3
[17] broom_0.5.5 haven_2.2.0 scales_1.1.0 generics_0.0.2
[21] farver_2.0.3 ellipsis_0.3.0 withr_2.1.2 cli_2.0.2
[25] magrittr_1.5 crayon_1.3.4 readxl_1.3.1 fs_1.4.1
[29] fansi_0.4.1 nlme_3.1-145 xml2_1.3.1 foreign_0.8-76
[33] class_7.3-15 tools_3.6.3 data.table_1.12.8 hms_0.5.3
[37] lifecycle_0.2.0 munsell_0.5.0 reprex_0.3.0 compiler_3.6.3
[41] e1071_1.7-3 rlang_0.4.5 classInt_0.4-2 units_0.6-6
[45] grid_3.6.3 rstudioapi_0.11 htmlwidgets_1.5.1 crosstalk_1.1.0.1
[49] labeling_0.3 gtable_0.3.0 codetools_0.2-16 DBI_1.1.0
[53] R6_2.4.1 gridExtra_2.3 lubridate_1.7.8 knitr_1.28
[57] rprojroot_1.3-2 KernSmooth_2.23-16 stringi_1.4.6 Rcpp_1.0.4
[61] vctrs_0.2.4 dbplyr_1.4.2 tidyselect_1.0.0 xfun_0.12
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.