geobr is an R package that allows users to easily download shapefiles of the Brazilian Institute of Geography and Statistics (IBGE) and other official spatial data sets of Brazil.
install.packages("geobr")
library(geobr)
The data.table
package has the operator %like%
, which is super handy for partial string matching:
"system with blue screen" %in% "blue"
> FALSE
"system with blue screen" %like% "blue"
> TRUE
# Libraries | |
library(geobr) | |
library(leafgl) | |
library(leaflet) | |
library(sf) | |
library(colourvalues) | |
# get data of disaster risk areas in Brazil using the geobr package |
### how to use R to find your most popular tweet of 2019 | |
# code by @nnstats | |
library(rtweet) | |
library(tidyverse) | |
library(lubridate) | |
show_most_popular_tweet <- function(user, year){ | |
y <- year |
R
and the geobr package to plot Brazilian metropolitan areas in different years.library(geobr)
library(dplyr)
library(ggplot2)
library(sf)
In this gist we show with a reproducible example how to create an animation of public transport networks using GTFS data in R
. We use a few packages to do this. One of the core packages here is the new gtfs2gps. The gtfs2gps package converts public transport data in GTFS format to GPS-like records in a data.frame/data.table
, which we will be using to create a .gif
with the gganimate
package.
The first step is to process a GTFS.zip
file. The function gtfs2gps{gtfs2gps}
interpolates the space-time position of each vehicle in each trip considering the network distance and average speed between stops. The output is a data.table
where each row represents the timestamp of each vehicle at a given spatial resolution. In this example, we use a sample of the public transport network of Sao Paulo (Brazil) mapped e
Color palette inspired by this gorgeous image of Mars landscape, captured by HiRISE (NASA) and processed by Seán Doran. I created this color scale with the help of Chroma.js Color Palette Helper.
Image credit: HiRISE & Seán Doran``` | |
################# 4) Build a Balanced Panel data set ------------------------------ | |
# data with one observation for each area each day, even if there was no notification on that day/area | |
# get all dates and munis | |
all_munis <- unique(df$code_muni) | |
all_dates <- seq(min(df$DT_NOTIFIC), | |
max(df$DT_NOTIFIC), | |
by = "day") |