5.4 Centroids
Centroid operations identify the center of geographic objects.
- Analogous to mean/median/mode, there are different ways to calculate centroids (chapter 11)
|>
nz ggplot() +
geom_sf() +
labs(title = "New Zealand",
subtitle = "where R was born!",
caption = "GeoComputation with R book club") +
theme_minimal()
head(nz) #New Zealand
## Simple feature collection with 6 features and 6 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 1568217 ymin: 5518431 xmax: 2089533 ymax: 6191874
## Projected CRS: NZGD2000 / New Zealand Transverse Mercator 2000
## Name Island Land_area Population Median_income Sex_ratio
## 1 Northland North 12500.561 175500 23400 0.9424532
## 2 Auckland North 4941.573 1657200 29600 0.9442858
## 3 Waikato North 23900.036 460100 27900 0.9520500
## 4 Bay of Plenty North 12071.145 299900 26200 0.9280391
## 5 Gisborne North 8385.827 48500 24400 0.9349734
## 6 Hawke's Bay North 14137.524 164000 26100 0.9238375
## geom
## 1 MULTIPOLYGON (((1745493 600...
## 2 MULTIPOLYGON (((1803822 590...
## 3 MULTIPOLYGON (((1860345 585...
## 4 MULTIPOLYGON (((2049387 583...
## 5 MULTIPOLYGON (((2024489 567...
## 6 MULTIPOLYGON (((2024489 567...
= st_centroid(nz) nz_centroid
## Warning: st_centroid assumes attributes are constant over geometries
|>
nz ggplot() +
geom_sf() +
geom_sf(color = "red", data = nz_centroid) +
labs(title = "New Zealand",
subtitle = "centroids",
caption = "GeoComputation with R book club") +
theme_minimal()
|>
nz ggplot() +
geom_sf() +
geom_sf_label(data = nz_centroid,
aes(label = Name)) +
labs(title = "New Zealand",
subtitle = "labels",
caption = "GeoComputation with R book club") +
theme_minimal()