suppressWarnings(if(!require("pacman")) install.packages("pacman"))
::p_load('tidyverse', 'sf', 'tmap', 'geojsonio', 'sp') pacman
Based on Adam Dennet’s Australian Population Studies
Modernized version of Adam’s accompanying : https://rpubs.com/adam_dennett/376877
As the name suggests, to run a spatial interaction model, you are going to need some spatial data and some data on interactions (flows). Let’s start with some spatial data:
library(sf)
# I/O for GeoJSON
library(geojsonio)
# Read geojson file as spatial object
<- geojson_read("https://www.dropbox.com/s/0fg80nzcxcsybii/GCCSA_2016_AUST_New.geojson?raw=1", what = "sp")
aus
# Read data as simple features object and set coordinate reference system
<- aus %>%
aus_sf st_as_sf() %>%
st_set_crs(4283)
%>%
aus_sf head()
# Now you may have noticed that the code order is a bit weird, so let's fix that and reorder
<- aus_sf %>%
aus_sf1 arrange(GCCSA_CODE)
# Now let's create an 'sp' object from our new ordered SF object
<- as_Spatial(aus_sf1) aus
Check your boundaries have downloaded ok
library(tmap)
tmap_mode("view")
#qtm(aus_sf)
%>%
aus_sf st_make_valid() %>%
tm_shape() +
tm_borders(col = "black", lwd = 2, alpha = 0.4) +
tm_fill(col = "gold", alpha = 0.1)