if (requireNamespace("USpopcenters", quietly = TRUE) &&
requireNamespace("geosphere", quietly = TRUE)) {
# All states whose centers of population are within 300 kilometers of the
# center of population of New York County, New York (i.e, Manhattan):
areas_in_radius(
geography = "state",
center = lon_lat_from_area(state = "NY", county = "New York"),
radius = 300,
units = "km"
)
# The four census tracts whose centers of population are closest to the
# Four Corners (distance column is in meters due to setting units = NULL):
closest_n_areas("tract", center = c(-109.0452, 36.9991), n = 4, units = NULL)
# The counties closest to center of population of Kauai County, Hawaii whose
# total population reaches 3 million people:
closest_population(
geography = "county",
center = lon_lat_from_area("15007"),
population = 3e6,
units = "barleycorns"
)
}
Run the code above in your browser using DataLab