knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

## Packages to use ----
pacman::p_load(tidyverse, janitor, writexl, 
              readxl, scales, mytidyfunctions,
              presupuestoR)

## Set theme ------
theme_set(theme_jmr(text = element_text()))

options(ggplot2.discrete.colour = c("#277DA1", "#f94144", "#F9C74F", "#43AA8B"),
        ggplot2.discrete.fill = c("#277DA1", "#f94144", "#F9C74F", "#43AA8B"))

presupuestoR

Español Este paquete proporciona una colección de funciones para el análisis presupuestario utilizando datos abiertos de Transparencia Presupuestaria.

English This package provides a collection of functions for budget analysis using open data from Transparency platform in Mexico.

Readme en español {#spanish}

Instalación

La versión en desarrollo puede ser instalada de GitHub con:

remotes::install_github("JavierMtzRdz/presupuestoR")
# Or
devtools::install_github("JavierMtzRdz/presupuestoR")   

Descripción general

Readme in English {#english}

Installation

You can install the development version of presupuestoR from GitHub with:

remotes::install_github("JavierMtzRdz/presupuestoR")
# Or
devtools::install_github("JavierMtzRdz/presupuestoR")   

Overview

Ejemplos / examples

sum_pef_tp() and id_ramo_to_abr_ramo()

This simple code estimates the approved budget for each ministry in 2022 and assign its abbreviation.

#| include: false

## Especificar locale ----
Sys.setlocale("LC_ALL", "es_ES.UTF-8")

## Desabilitar notación científica.----
options(scipen = 999)

pacman::p_load(tidyverse, janitor, writexl, 
               readxl, scales, mytidyfunctions, presupuestoR)

budget_2022 <- read_excel("misc/pef_ac01_avance_3t_2022.xlsx", 
           guess_max = 1000000) %>% 
  clean_names() %>% 
  rename(aprobado = contains("monto_pef_2023")) %>% 
  data.table::setDT()
#| echo: true

budget_ministery <- budget_2022 %>% 
  sum_pef_tp(id_ramo,
             keep_mensual = F) %>% 
  mutate(abr_ramo = id_ramo_to_abr_ramo(id_ramo),
         aprobado = aprobado/1000000) %>% 
  select(abr_ramo, aprobado)

budget_ministery

deflactar_tp()

This code estimates the value of the approved budget in 2022 with 2010 prices in a few lines of code.

#| echo: true

budget_ministery %>% 
  mutate(aprobado_2010_prices = 
           deflactar_tp(aprobado, 
                        2022,
                        2010))

netear_tp() and negative_neteo_tp()

Here, the total net State spending for 2022 is estimated in three lines of code.

#| echo: true

budget_2022 %>% 
  netear_tp() %>% 
  negative_neteo_tp() %>% 
  sum_pef_tp() %>% 
  transmute(comma(aprobado))

indexing()

In this example, the GDP per capita for Oceania countries is indexed to the year 1952.

# Load the gapminder library
library(gapminder)

# Select Oceania countries from the gapminder dataset
oc_gapminder <- gapminder %>% 
  filter(continent == "Oceania") 

# Display the first few rows of the Oceania dataset
oc_gapminder %>% 
  arrange(year) %>% 
  head()

# Create a country-wise index based on GDP per capita for the year 1952
idx_gap <- oc_gapminder %>% 
  group_by(country) %>% 
  indexing(gdpPercap,
           year == 1952) 

# Display the first few rows of the indexed dataset
idx_gap %>% 
  arrange(year) %>% 
  head()

# Compare indexes across countries using a line plot
idx_gap %>% 
  ggplot(aes(x = year, 
             y = index,
             color = country)) +
  geom_line() 


JavierMtzRdz/presupuestoR documentation built on June 11, 2024, 11:38 a.m.