View source: R/summarise-SpatVector.R
| summarise.SpatVector | R Documentation |
SpatVector down to one geometrysummarise() creates a new SpatVector. It returns one geometry for each
combination of grouping variables; if there are no grouping variables, the
output will have a single geometry summarising all observations in the input
and combining all the geometries of the SpatVector. It will contain one
column for each grouping variable and one column for each of
the summary statistics that you have specified.
summarise.SpatVector() and summarize.SpatVector() are synonyms
## S3 method for class 'SpatVector'
summarise(.data, ..., .by = NULL, .groups = NULL, .dissolve = TRUE)
## S3 method for class 'SpatVector'
summarize(.data, ..., .by = NULL, .groups = NULL, .dissolve = TRUE)
.data |
A |
... |
< The value can be:
|
.by |
Ignored on this method ( |
.groups |
See |
.dissolve |
logical. Should borders between aggregated geometries be dissolved? |
A SpatVector.
terra::aggregate()
Implementation of the generic dplyr::summarise() function.
SpatVectorSimilarly to the implementation on sf this function can be used to
dissolve geometries (with .dissolve = TRUE) or create MULTI versions of
geometries (with .dissolve = FALSE). See Examples.
dplyr::summarise(), terra::aggregate()
Other single table verbs:
arrange.SpatVector(),
filter.Spat,
mutate.Spat,
rename.Spat,
select.Spat,
slice.Spat
Other dplyr verbs that operate on group of rows:
count.SpatVector(),
group-by.SpatVector,
rowwise.SpatVector()
Other dplyr methods:
arrange.SpatVector(),
bind_cols.SpatVector,
bind_rows.SpatVector,
count.SpatVector(),
distinct.SpatVector(),
filter-joins.SpatVector,
filter.Spat,
glimpse.Spat,
group-by.SpatVector,
mutate-joins.SpatVector,
mutate.Spat,
pull.Spat,
relocate.Spat,
rename.Spat,
rowwise.SpatVector(),
select.Spat,
slice.Spat
library(terra)
library(ggplot2)
v <- vect(system.file("extdata/cyl.gpkg", package = "tidyterra"))
# Grouped
gr_v <- v %>%
mutate(start_with_s = substr(name, 1, 1) == "S") %>%
group_by(start_with_s)
# Dissolving
diss <- gr_v %>%
summarise(n = dplyr::n(), mean = mean(as.double(cpro)))
diss
autoplot(diss, aes(fill = start_with_s)) + ggplot2::ggtitle("Dissolved")
# Not dissolving
no_diss <- gr_v %>%
summarise(n = dplyr::n(), mean = mean(as.double(cpro)), .dissolve = FALSE)
# Same statistic
no_diss
autoplot(no_diss, aes(fill = start_with_s)) +
ggplot2::ggtitle("Not Dissolved")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.