Spatial Representation of distantia()
Data Frames
Source: R/distantia_spatial.R
distantia_spatial.Rd
Given an sf data frame with geometry types POLYGON, MULTIPOLYGON, or POINT representing time series locations, this function transforms the output of distantia()
, distantia_ls()
, distantia_dtw()
or distantia_time_shift()
to an sf data frame.
If network = TRUE
, the sf data frame is of type LINESTRING, with edges connecting time series locations. This output is helpful to build many-to-many dissimilarity maps (see examples).
If network = FALSE
, the sf data frame contains the geometry in the input sf
argument. This output helps build one-to-many dissimilarity maps.
Arguments
- df
(required, data frame) Output of
distantia()
ordistantia_time_shift()
. 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- network
(optional, logical) If TRUE, the resulting sf data frame is of time LINESTRING and represent network edges. Default: TRUE
See also
Other distantia_support:
distantia_aggregate()
,
distantia_boxplot()
,
distantia_cluster_hclust()
,
distantia_cluster_kmeans()
,
distantia_matrix()
,
distantia_model_frame()
,
distantia_stats()
,
distantia_time_shift()
,
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_psi <- distantia::distantia_spatial(
df = df_psi,
sf = distantia::covid_counties,
network = TRUE
)
#subset target counties
counties <- c("Los_Angeles", "San_Francisco", "Fresno", "San_Joaquin")
sf_psi_subset <- sf_psi[
which(sf_psi$x %in% counties & sf_psi$y %in% counties), ]
#network map
# mapview::mapview(
# distantia::covid_counties,
# col.regions = NA,
# alpha.regions = 0,
# color = "black",
# label = "name",
# legend = FALSE,
# map.type = "OpenStreetMap"
# ) +
# mapview::mapview(
# sf_psi_subset,
# layer.name = "Psi",
# label = "edge_name",
# zcol = "psi",
# lwd = 3
# ) |>
# suppressWarnings()
#one to many
sf_psi <- distantia_spatial(
df = df_psi,
sf = distantia::covid_counties,
network = FALSE
)
#subset one county
sf_psi_subset <- sf_psi[sf_psi$x == "Los_Angeles", ]
#one to many map
#dissimilarity of all counties with Los Angeles
# mapview::mapview(
# sf_psi_subset,
# layer.name = "Psi with LA",
# label = "y",
# zcol = "psi",
# alpha.regions = 1
# ) |>
# suppressWarnings()