Este cuaderno permitira identificar los cultivos mas importantes en el departamento de Santander en Colombia, se obtuvo el archivo de EVA (Evaluaciones Agropecuarias Municipales), tomados de la UPRA como la base de datos para el año 2020, basado tambien en una consulta de adiciomal para determinar los cultivos con mejor rendiemiento en la zona y asi poder hacer una mejor filtracion de la informacion.
#install.packages('tidyverse')
#install.packages("readxl")
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.6.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(readxl)
library(readr)
## Warning: package 'readr' was built under R version 3.6.3
###LEER ARCHIVO
(archivos = list.files(pattern='xls'))
## [1] "20210624_BaseSIPRA2020.xlsx"
(hojas = excel_sheets("20210624_BaseSIPRA2020.xlsx"))
## [1] "Agrícola_SIPRA_AGRONET" "InventarioBovino"
## [3] "InventarioPorcino" "InvBufalosCaprinoOvinoEquino"
## [5] "InvAves"
eva2020 = read_excel("20210624_BaseSIPRA2020.xlsx", sheet = "Agrícola_SIPRA_AGRONET")
eva2020
stder2020 = dplyr::filter(eva2020, Departamento == "Santander")
stder2020
stder2020.tmp <- stder2020 %>% select('Código del Municipio':'Ciclo del cultivo')
stder2020.tmp
stder2020.tmp %>% rename(Cod_Mun = 'Código del Municipio',
Grupo = 'Grupo cultivo según especie',
Subgrupo = 'Subgrupo cultivo según especie',
AreaSiembra = 'Area Sembrada (ha)',
AreaCosecha = 'Area Cosechada (ha)',
Produccion = 'Producción (t)',
Rendimiento = 'Rendimiento (t/ha)', Ciclo='Ciclo del cultivo') -> nstder2020
nstder2020 %>% mutate(AreaSiembra = as.numeric(AreaSiembra),
AreaCosecha = as.numeric(AreaCosecha),
Produccion = as.numeric(Produccion),
Rendimiento = as.numeric(Rendimiento)) -> nstder2020
nstder2020
nstder2020 %>%
filter(Produccion > 0) %>%
group_by(Cultivo) %>%
summarize(total_produccion = sum(Produccion)) %>%
arrange(desc(total_produccion))
nstder2020
nstder2020 %>%
group_by(Cultivo, Municipio) %>%
summarize(max_prod = max(Produccion, na.rm = TRUE)) %>%
slice(which.max(max_prod)) %>%
arrange(desc(max_prod))
## `summarise()` has grouped output by 'Cultivo'. You can override using the `.groups` argument.
## `summarise()` has grouped output by 'Cultivo'. You can override using the `.groups` argument.
nstder2020 %>%
group_by(Grupo,Municipio) %>%
summarize(max_prod = max(Produccion, na.rm = TRUE)) %>%
slice(which.max(max_prod)) %>%
arrange(desc(max_prod))
## `summarise()` has grouped output by 'Grupo'. You can override using the `.groups` argument.
## `summarise()` has grouped output by 'Grupo'. You can override using the `.groups` argument.
nstder2020 %>%
group_by(Cod_Mun, Municipio, Grupo) %>%
filter(Grupo=='Frutales') %>%
summarize(max_prod = max(Produccion, na.rm = TRUE)) %>%
arrange(desc(max_prod)) -> frutales2020
## `summarise()` has grouped output by 'Cod_Mun', 'Municipio'. You can override using the `.groups` argument.
## `summarise()` has grouped output by 'Cod_Mun', 'Municipio'. You can override using the `.groups` argument.
frutales2020
nstder2020 %>%
group_by(Cod_Mun, Municipio, Grupo) %>%
filter(Grupo=='Leguminosas Y Oleaginosas') %>%
summarize(max_prod = max(Produccion, na.rm = TRUE)) %>%
arrange(desc(max_prod)) -> oleaginosas2020
## `summarise()` has grouped output by 'Cod_Mun', 'Municipio'. You can override using the `.groups` argument.
## `summarise()` has grouped output by 'Cod_Mun', 'Municipio'. You can override using the `.groups` argument.
oleaginosas2020
#write_csv(frutales2020, "./stder_frutales_2020.csv")
write_csv(oleaginosas2020, "./stder_oleag_2020.csv")