Skip to content

Instantly share code, notes, and snippets.

View rafapereirabr's full-sized avatar

Rafael H M Pereira rafapereirabr

View GitHub Profile
@rafapereirabr
rafapereirabr / clean_polygons_remove_slivers.md
Last active August 16, 2023 01:42
Clean polygons to remove slivers

Trying different methods to clean polygons to remove slivers

Load libraries

library(sf)
library(dplyr)
library(lwgeom)

# using planar geometry
sf::sf_use_s2(FALSE)
@rafapereirabr
rafapereirabr / walking_isochrone_sao_paulo_r5r.R
Created August 14, 2023 14:49
walking isochrone Sao Paulo with r5r
library(r5r)
library(mapview)
# build transport network
data_path <- system.file("extdata/spo", package = "r5r")
r5r_core <- setup_r5(data_path)
# load origin/destination points
points <- read.csv(file.path(data_path, "spo_hexgrid.csv"))
origin_1 <- subset(points, id =='89a8100c393ffff')
@rafapereirabr
rafapereirabr / flight_passengers_sdu_gig.R
Created August 8, 2023 22:58
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') |
@rafapereirabr
rafapereirabr / heatmap_pseudo_log.R
Created February 12, 2023 15:51
heat map with pseudo_log scale
# Library
library(ggplot2)
library(viridis)
# Dummy data
set.seed(42)
x <- LETTERS[1:20]
y <- paste0("var", seq(1,20))
data <- expand.grid(X=x, Y=y)
data$Z <- runif(400, 0, 10000)
@rafapereirabr
rafapereirabr / test_gdalio.R
Created December 29, 2022 18:07
generating aerial images with gdalio
library(sf)
library(terra)
library(gdalio)
library(geobr)
### Choose either a small or large area
i = 49 # small area
i = 1066 # large area
@rafapereirabr
rafapereirabr / visualizing_gtfs_frequency.md
Created August 31, 2022 17:00
Visualizing transit frequencies from GTFS data
library(gtfstools)

# read gtfs
data_path <- system.file("extdata/spo_gtfs.zip", package = "gtfstools")
gtfs <- read_gtfs(data_path)

# merge trips and freq
trip_df <- merge(gtfs$trips, gtfs$frequencies)
@rafapereirabr
rafapereirabr / cobranca_de_bagagens.md
Last active April 27, 2022 18:03
cobranca_de_bagagens.

análise rápida dos dados de evolução diária do N. de bagagens pagas e gratuidas X Km

Download data

#' data downloaded from ANAC using flightsbr, https://github.com/ipeaGIT/flightsbr
#' data dictionary at https://www.gov.br/anac/pt-br/assuntos/regulados/empresas-aereas/envio-de-informacoes/descricao-de-variaveis

library(flightsbr)
library(data.table)
@rafapereirabr
rafapereirabr / air_passenger_demand_BR.R
Last active March 17, 2022 14:47
Comparing air passenger demand over time in Brazil
#' Comparing air passenger demand over time in Brazil
#' Reproducible code to create a figure visualizing how daily air passenger demand in Brazil has changed over time.
### Load libraries
library(ggplot2)
library(flightsbr)
library(lubridate)
library(data.table)
@rafapereirabr
rafapereirabr / path_tree_r5r.md
Last active June 25, 2022 05:00
Map of cycling, walking and driving routes in R using r5r

Creating a map of cycling, walking and driving routes in R

Quick reproducible example showing how to use the r5r package to estimate cycling, walking and driving routes in R.

Prepare R environment

options(java.parameters = "-Xmx4G")

library(r5r)
library(geobr)