
Convert Dissimilarity Analysis Data Frames to Spatial Dissimilarity Networks
Source:R/distantia_spatial_network.R
distantia_spatial_network.Rd
Given an sf data frame with the coordinates of a time series list transforms a data frame resulting from distantia()
to an sf data frame with lines connecting the time series locations. This can be used to visualize a geographic network of similarity/dissimilarity between locations. See example for further details.
Arguments
- df
(required, data frame) Output of
distantia()
ordistantia_aggregate()
. Default: NULL- sf
(required, sf data frame) Points or polygons representing the location of the time series in argument 'df'. It must have a column with all time series names in
df$x
anddf$y
. Default: NULL- one_to_many
(optional, logical) If TRUE, the resulting data frame is reorganized to help map one-to-many relationships using the original geometry in
sf
rather than network edges. Default: FALSE
See also
Other distantia_support:
distantia_aggregate()
,
distantia_boxplot()
,
distantia_cluster_hclust()
,
distantia_cluster_kmeans()
,
distantia_dtw_shift()
,
distantia_matrix()
,
distantia_model_frame()
,
distantia_stats()
,
utils_block_size()
,
utils_cluster_hclust_optimizer()
,
utils_cluster_kmeans_optimizer()
,
utils_cluster_silhouette()
Examples
tsl <- distantia::tsl_initialize(
x = distantia::covid_prevalence,
name_column = "name",
time_column = "time"
)
df_psi <- distantia::distantia_ls(
tsl = tsl
)
#network many to many
sf_network <- distantia::distantia_spatial_network(
df = df_psi,
sf = distantia::covid_counties
)
#subset target counties
counties <- c("Los_Angeles", "San_Francisco", "Fresno", "San_Joaquin")
sf_network_subset <- sf_network[
which(sf_network$x %in% counties & sf_network$y %in% counties), ]
#network map
# mapview::mapview(
# distantia::covid_counties,
# col.regions = NA,
# color = "black",
# label = "name",
# legend = FALSE,
# map.type = "OpenStreetMap"
# ) +
# mapview::mapview(
# sf_network_subset,
# layer.name = "Psi",
# label = "edge_name",
# zcol = "psi",
# lwd = 3
# ) |>
# suppressWarnings()
#one to many
sf_network <- distantia_spatial_network(
df = df_psi,
sf = distantia::covid_counties,
one_to_many = TRUE
)
#subset one county
sf_network_subset <- sf_network[sf_network$x == "Los_Angeles", ]
#one to many map
#dissimilarity of all counties with Los Angeles
# mapview::mapview(
# sf_network_subset,
# layer.name = "Psi with LA",
# label = "y",
# zcol = "psi",
# alpha.regions = 1
# ) |>
# suppressWarnings()