Skip to content

Instantly share code, notes, and snippets.

@sientifiko
Created December 11, 2023 20:06
Show Gist options
  • Save sientifiko/aef10e94b3dfc24f51a3dfe306c54b63 to your computer and use it in GitHub Desktop.
Save sientifiko/aef10e94b3dfc24f51a3dfe306c54b63 to your computer and use it in GitHub Desktop.
Generar gráficas sobre PIB argentina
library(tidyverse)
library(directlabels)
theme_set(theme_bw(base_size = 21))
options(scipen = 999)
dat <- readxl::read_excel("mpd2020.xlsx", sheet = 3) %>%
filter(country %in% c("Argentina", "Chile", "Brazil","Sweden", "United States",
"Norway", "Uruguay", "United Kingdom", "Panama"),
year >= 1870)
dat$gdppc
dat %>%
filter(country %in% c("Argentina","Sweden", "United States",
"Norway", "United Kingdom")) %>%
ggplot() +
aes(year, gdppc, color = country) +
guides(color = "none") +
geom_line(size = 1.5) +
geom_dl(aes(label = country),
method = list(dl.trans(x = x + 0), "last.points", cex = 1)) +
scale_y_continuous(trans = "log10") +
scale_x_continuous(breaks = seq(1870, 2035, 5), limits = c(1870, 2035),
expand = c(0, 0)) +
theme(axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.x = element_text(angle = 90, vjust = .5)) +
labs(title = "PIB pc real PPA a US$2011",
subtitle = "Eje Y en log10")
pivdat <- dat %>%
select(country, year, gdppc) %>%
filter(country %in% c("Argentina", "Chile", "Brazil",
"Norway", "Uruguay", "Panama")) %>%
spread(country, gdppc)
pivdat$ARG <- pivdat$Argentina/pivdat$Norway
pivdat$CHL <- pivdat$Chile/pivdat$Norway
pivdat$BRZ <- pivdat$Brazil/pivdat$Norway
pivdat$URY <- pivdat$Uruguay/pivdat$Norway
pivdat %>%
select(year, 8:11) %>%
gather("pais", "pibpc", 2:5) %>%
ggplot() +
aes(year, pibpc, color = pais) +
guides(color = "none") +
geom_line(size = 1.5) +
geom_dl(aes(label = pais),
method = list(dl.trans(x = x + 0), "first.points", cex = 1)) +
geom_hline(yintercept = 1) +
scale_x_continuous(breaks = seq(1865, 2018, 5), limits = c(1865, 2018),
expand = c(0, 0)) +
theme(axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.x = element_text(angle = 90, vjust = .5)) +
labs(title = "PIB pc relativo a Noruega",
subtitle = "Mayor a 1 PIB mayor a Noruega, y viceversa")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment