Explore: covariates association
Exploring association between covariates used for land suitability modelling.
Load packages, read data and source custom scripts
rm(list = ls())
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
library(GGally)
#> Registered S3 method overwritten by 'GGally':
#> method from
#> +.gg ggplot2
path_proj <- day2day::git_path()
path_data <- file.path(path_proj, "data")
path_processed <- file.path(path_data, "processed")
land_cover <- fst::read_fst(file.path(path_processed, "uk_1km_df_model.fst"))
Custom functions for ggpairs
gg_hex <- function(data, mapping, ...) {
ggplot(data = data, mapping = mapping) +
geom_hex(na.rm = TRUE, ...) +
geom_smooth(aes(color = "gg_red"), data = dplyr::sample_frac(data, 0.2)) +
colorspace::scale_fill_continuous_sequential("Viridis", trans = "log")
}
gg_hist <- function(data, mapping, ...) {
ggplot(data = data, mapping = mapping) +
geom_histogram(fill = "gray", bins = 100)
}
Visualise covariates association for urban variables
land_cover %>%
dplyr::select(pop:gdhi) %>%
ggpairs(lower = list(continuous = gg_hex), diag = list(continuous = gg_hist)) +
theme_bw()
Visualise covariates association for environmental variables
land_cover %>%
dplyr::select(elev:slope_nb8, gdd:sms) %>%
ggpairs(lower = list(continuous = gg_hex), diag = list(continuous = gg_hist)) +
theme_bw()
Time to execute the task
Only useful when executed with Rscript
.
proc.time()
#> user system elapsed
#> 102.068 1.254 103.271