View source: R/geom_centroids.R
| geom_centroids | R Documentation | 
Assigns each point a longitude and latitude corresponding to the geographic
centre of its administrative area. This means that all points in the same
area will overlap. The default position uses position_circle_repel()
to repel the points outwards with an amount controllable with its
scale parameter.
geom_centroids(
  mapping = ggplot2::aes(),
  data = NULL,
  stat = "automap_coords",
  position = "circle_repel_sf",
  ...,
  fun.geometry = NULL,
  feature_type = NA,
  inset = NA,
  map_base = "clip",
  map_inset = "auto",
  na.rm = TRUE,
  show.legend = "point",
  inherit.aes = TRUE
)
| mapping, data, stat, position, na.rm, show.legend, inherit.aes, ... | See  | 
| fun.geometry | A function that takes a  | 
| feature_type | Type of map feature. See  | 
| inset | Inset configuration; see  | 
| map_base | Controls the layer with the base map. Possible values are
 | 
| map_inset | Controls the layer with the inset map. Possible values are
 | 
A ggplot layer.
The location aesthetic is required.
geom_centroids() understands the same aesthetics as ggplot2::geom_point().
library(ggplot2)
cartographer::nc_type_example_2 |>
  head(n = 100) |>
  ggplot(aes(location = county)) +
  geom_boundaries(feature_type = "sf.nc") +
  geom_centroids(aes(colour = type), position = position_circle_repel_sf(scale = 6), size = 0.5) +
  coord_automap(feature_type = "sf.nc")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.