library(sf)
library(ggplot2)
library(mapview)
library(lwgeom)
library(rnaturalearth)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## This gist shows how to create Flow Maps in R using ggplot2. | |
## source: This is based on different bits of code from other with amazing R skills: | |
@ceng_l : http://web.stanford.edu/~cengel/cgi-bin/anthrospace/great-circles-on-a-recentered-worldmap-in-ggplot | |
@3wen : http://egallic.fr/maps-with-r/ | |
@spatialanalysis : http://spatialanalysis.co.uk/2012/06/mapping-worlds-biggest-airlines/ | |
@freakonometrics : http://freakonometrics.hypotheses.org/48184 | |
# Libraries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sfdep) | |
library(data.table) | |
library(cppRouting) | |
# get distance between neighbors | |
geo <- sf::st_geometry(guerry) | |
nb <- sfdep::st_contiguity(geo) | |
dists <- sfdep::st_nb_dists(geo, nb) |
This gist shows in two steps how to tilt and stack maps using ggplot2 in order to create an image like this one: [![enter image description here][1]][1]
Let's load the necessary libraries and data to use a reproducible example:
# load libraries
library(rgeos)
library(UScensus2000tract)
library(ggplot2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(stringr) | |
library(spdep) | |
library(rgdal) | |
library(magrittr) | |
library(ggplot2) | |
library(sf) | |
#====================================================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sf) | |
library(terra) | |
library(gdalio) | |
library(geobr) | |
### Choose either a small or large area | |
i = 49 # small area | |
i = 1066 # large area |
NewerOlder