View source: R/lsp_add_clusters.R
lsp_add_clusters | R Documentation |
Adds clusters' ids to a lsp object.
The output can be of stars
, sf
, or terra
class.
See examples.
lsp_add_clusters(x, clust, output = "sf", window = NULL)
x |
Object of class |
clust |
Vector containing an id value for each row in |
output |
The class of the output. Either |
window |
Specifies areas for analysis. It can be either: |
Object of class stars
, sf
, or terra
(depending on the output
argument) with an additional column "clust"
representing clusters' id values.
library(stars)
library(sf)
landform = read_stars(system.file("raster/landforms.tif", package = "motif"))
landform_cove = lsp_signature(landform,
type = "cove",
window = 200,
normalization = "pdf")
landform_dist = lsp_to_dist(landform_cove,
dist_fun = "jensen-shannon")
landform_hclust = hclust(landform_dist, method = "ward.D2")
#plot(landform_hclust)
clusters = cutree(landform_hclust, k = 4)
landform_grid_sf = lsp_add_clusters(landform_cove, clusters)
#plot(landform_grid_sf["clust"])
#landform_grid_sfq = lsp_add_quality(landform_grid_sf,
# landform_dist)
#plot(landform_grid_sfq["quality"])
## larger data example
# library(stars)
# library(sf)
# landform = read_stars(system.file("raster/landform.tif", package = "motif"),
# proxy = FALSE)
# landform_cove = lsp_signature(landform,
# type = "cove",
# window = 200,
# normalization = "pdf")
#
# landform_dist = lsp_to_dist(landform_cove,
# dist_fun = "jensen-shannon")
#
# landform_hclust = hclust(landform_dist, method = "ward.D2")
# plot(landform_hclust)
#
# clusters = cutree(landform_hclust, k = 6)
#
# landform_grid_sf = lsp_add_clusters(landform_cove, clusters)
# plot(landform_grid_sf["clust"])
#
# landform_grid_sfq = lsp_add_quality(landform_grid_sf,
# landform_dist)
# plot(landform_grid_sfq["quality"])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.