| lsp_add_clusters {motif} | R Documentation | 
Adds clusters' ids to a lsp object
Description
Adds clusters' ids to a lsp object.
The output can be of stars, sf, or terra class.
See examples.
Usage
lsp_add_clusters(x, clust, output = "sf", window = NULL)
Arguments
| 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:  | 
Value
Object of class stars, sf, or terra (depending on the output argument) with an additional column "clust" representing clusters' id values.
Examples
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"])
[Package motif version 0.6.4 Index]