quick code snippet to create (weighted) quantiles in R
using data.table
.
library(data.table)
library(Hmisc)
# create data.table
n <- 100000
``` | |
library(sf) | |
library(geobr) | |
# sample spatial data | |
df <- read_state() | |
# create random pop and cases | |
df$pop <- sample(1:27, 27, replace = T) |
A simple reproducible Hexsticker for r5r, a package for Rapid Realistic Routing with R5 in R.
### Libraries ------------------------
remotes::install_github("GuangchuangYu/hexSticker")
library(hexSticker) # https://github.com/GuangchuangYu/hexSticker
library(ggplot2)
library(sf)
library(geobr) | |
library(sf) | |
library(mapview) | |
library(stringr) | |
mapviewOptions(platform = 'leafgl') | |
# read original census tracts | |
urban_cts <- read_census_tract(year = 2000, code_tract = 'RJ', zone ='urban', simplified = F) | |
rural_cts <- read_census_tract(year = 2000, code_tract = 'RJ', zone ='rural', simplified = F) |
library(ggmap)
library(data.table)
# registrar Google API Key
register_google(key = 'xxxxx-xxxxxx-xxxxx-xxxxx')
library(googleAnalyticsR) | |
library(data.table) | |
library(ggplot2) | |
library(dplyr) | |
library(rworldmap) | |
library(sf) | |
options(scipen=999) | |
## setup | |
ga_auth() |
library(geobr) | |
library(ggplot2) | |
library(sf) | |
library(sfheaders) | |
df <- read_municipality(year=2018) | |
centrd <- st_centroid(df) | |
centrd <- sfheaders::sf_to_df(centrd, fill=T) | |
df$position <- centrd$y + centrd$x |
library(gtfs2gps) | |
library(gtfsrouter) | |
# original process | |
sp <- system.file("extdata/saopaulo.zip", package ="gtfs2gps") | |
time_gps <- system.time(gps_gps <- gtfs2gps(sp, parallel = T, spatial_resolution = 200)) | |
#' Code by Rafael H. M. Pereira and Marcus Saraiva | |
#' | |
#' Radiation model (Simini et al 2012) | |
#' Tij = Ti * ((Pi * Pj) / ((Pi + Pij) * (Pi + Pj + Pij))) | |
#' | |
#' Where: | |
#' | |
#' Tij: Avarage flux between origin i and destination j predicted by the radiation model | |
#' Ti: Proportion of population in i relative to total population | |
#' Pi: Absolute population in i |