Skip to content

Instantly share code, notes, and snippets.

@gabrielzanlorenssi
Last active October 17, 2019 21:10
Show Gist options
  • Save gabrielzanlorenssi/6ef2b75f9248b80d3055e5a348d14eeb to your computer and use it in GitHub Desktop.
Save gabrielzanlorenssi/6ef2b75f9248b80d3055e5a348d14eeb to your computer and use it in GitHub Desktop.
## Code to generate divida liquida plots
# Library -----------------------------------------------------------------
library(tidyverse)
library(readxl)
library(lubridate)
# Data --------------------------------------------------------------------
# data available here: https://drive.google.com/file/d/1J_eQuY4i41Od5Ln6rsgTAJJY583-j5x1/view?usp=sharing
data <- read_excel("./data/DividaLiquida.xls", skip=1) %>%
{. ->> data} %>%
set_names("level", "variable", 3:length(data)) %>%
gather(time, value, -level, -variable) %>%
mutate(date = dmy("1-11-2001") + months(as.numeric(time)-2))
# Plot --------------------------------------------------------------------
## debt as share of the gdp
data %>%
filter(level == "Liq total") %>%
filter(variable %in%
c("Governo federal", "Governos municipais", "Governos estaduais")) %>%
mutate(variable =
fct_recode(variable, `Federal Gov.`="Governo federal",
states="Governos estaduais", municipalities="Governos municipais")) %>%
ggplot(aes(x=date, y=value)) +
geom_line(aes(col=variable, group=variable), size=1.1) +
scale_x_date(breaks = seq(as.Date("2002-12-01"), as.Date("2018-12-01"), by="48 months"),
date_labels = "%m-%Y") +
labs(y="% of the GDP",
x="", title="Brazilian net public debt as a percentage of the GDP") +
theme_minimal(base_size = 18) +
theme(legend.position = "bottom", legend.box="horizontal") +
theme(panel.grid = element_line(linetype = "dashed",
size = 0.1,
colour = "black")) +
theme(text = element_text(family = "Bebas Neue")) +
# Bebas Neue font has to be installed and imported using extrafont package
theme(axis.line = element_line(size=0.2)) +
theme(plot.title = element_text(hjust = 0.5)) +
theme(legend.margin=margin(t=0, r=0, b=0, l=0, unit="cm")) +
scale_y_continuous(limits=c(0,50)) +
scale_color_manual(values=c("#FF3400", "#A60CE8", "#EBB605"), "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment