Commit 2e6513c7 authored by Nicolas Lambert's avatar Nicolas Lambert
Browse files

vignette

parent 22d53198
......@@ -4,6 +4,79 @@ knitr::opts_chunk$set(
comment = "#>"
)
## ----setup--------------------------------------------------------------------
## ----eval= FALSE--------------------------------------------------------------
# devtools::install_git(url = "https://gitlab.huma-num.fr/nlambert/flowmapper")
## -----------------------------------------------------------------------------
library(flowmapper)
## ----out.width = 200----------------------------------------------------------
library(sf)
# Import
crs <- "+proj=robin +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"
subregions <- st_read(system.file("subregions.gpkg", package="flowmapper")) %>% st_transform(crs)
migr <- read.csv(system.file("migrantstocks2019.csv", package="flowmapper"))
# Selection, filtrage, traitement en amont
threshold <- 1500
migr <- migr[migr$fij >= threshold,]
## -----------------------------------------------------------------------------
c <- plotflows(
x = subregions,
xid = "id",
df = migr,
dfid = c("i","j"),
dfvar = "fij"
)
## -----------------------------------------------------------------------------
intra <- migr[migr$i == migr$j,c("i","fij")]
colnames(intra) <- c("id","nb")
plot(st_geometry(subregions), col = "#CCCCCC", border = "white", lwd = 0.5)
c <- plotflows(
x = subregions,
xid = "id",
df = migr,
dfid = c("i","j"),
dfvar = "fij",
size = "thickness",
type = "rect",
decreasing = FALSE,
add = TRUE,
lwd = 1,
col = "#00FF0090",
border = "#4a0c25",
k = NULL,
df2 = intra,
df2id = "id",
df2var = "nb"
)
## -----------------------------------------------------------------------------
crs <- "+proj=aeqd +lat_0=90 +lon_0=50 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs "
subregions2 <- st_transform(subregions, crs)
plot(st_geometry(subregions2), col = "#CCCCCC", border = "white", lwd = 0.5)
c <- plotflows(
x = subregions2,
xid = "id",
df = migr,
dfid = c("i","j"),
dfvar = "fij",
add = TRUE
)
## -----------------------------------------------------------------------------
crs <- "+proj=ortho +lat_0=42.5333333333 +lon_0=-72.53333333339999 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs"
flows <- smoothr::densify(c[[3]], n = 30) %>% st_transform(crs)
plot(st_geometry(subregions) %>% st_transform(crs), col ="#CCCCCC", border = "white")
plot(st_geometry(flows), col ="#FF000099", add = TRUE)
plot(st_centroid(st_geometry(c[[2]])) %>% st_transform(crs), add = TRUE, pch = 20, cex = 1.3, col ="black")
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment