Skip to content

Instantly share code, notes, and snippets.

@rafapereirabr
Created August 8, 2023 22:58
Show Gist options
  • Save rafapereirabr/efa4ccd1febe597c15226b4ae141ec41 to your computer and use it in GitHub Desktop.
Save rafapereirabr/efa4ccd1febe597c15226b4ae141ec41 to your computer and use it in GitHub Desktop.
Comparing number of passengers using Rio's airports
library(flightsbr)
library(ggplot2)
library(data.table)
# download data
df <- flightsbr::read_flights(date = 2019:2023)
# filters
df <- df[ nr_ano_chegada_real >= 2019,]
df_rj <- df[ sg_iata_origem %in% c('SDU', 'GIG') |
sg_iata_destino %in% c('SDU', 'GIG'),]
df_rj <- df_rj[ !(nr_ano_chegada_real==2023 & nr_mes_chegada_real>6)]
df_rj[, airport := fifelse(sg_iata_origem=='SDU' | sg_iata_destino=='SDU', 'SDU', 'GIG')]
# count passengers
df_rj_pas <- df_rj[, .(nr_passag_pagos = sum(nr_passag_pagos)),
by = .(nr_ano_chegada_real, nr_mes_chegada_real, airport)]
# plot
ggplot(data=df_rj_pas) +
geom_line(aes(x= nr_mes_chegada_real,
y = nr_passag_pagos/1000,
color= airport)) +
labs( x = 'Mês', y='Número de passageiros (em milhares)',
caption = 'credit: @UrbanDemog using {flightsbr}') +
facet_wrap(.~nr_ano_chegada_real, ncol = 5) +
scale_x_continuous(breaks = c(1, 4, 7, 10)) +
scale_color_manual(labels=c('Galeão (GIG)', 'Santos Dumont (SDU)'),
values = c('#019a99', '#feb857'), name='') +
theme_classic() +
theme(legend.position = c(.7,0.85))
ggsave(filename = 'f.png', dpi=300,
width = 16, height = 10, units = 'cm')
@rafapereirabr
Copy link
Author

f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment