Skip to content

datadiversitylab/city_clusters

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

World Cities Clustering

An R repository that takes raw spatial data to the final clustering results for A global framework to compare cities for research in urban evolutionary ecology and related fields. It extracts climatic and anthropogenic features for the world's cities, selects the best number of clusters for each dataset from the data, and generates the manuscript's tables and figures.

Inputs

Place these in data/ before running:

data/
  shapefile/   city boundaries (Patterson & Kelso). Set SHP / NAME_FIELD /
               REGION_FIELD at the top of 01_extract_features.R.
  rasters/     source rasters named per the manifest in 01_extract_features.R:
                 elevation.tif, brightness.tif, human_mod.tif, roads.tif,
                 cropland.tif, grazing.tif, pop_2000.tif, pop_2021.tif

Feature split

  • Climatic: 19 CHELSA bioclim variables + Elevation
  • Anthropogenic: area, brightness, human modification, population (2000, 2021, change), crop land, grazing land, road density
  • Combined: all of the above

Running

From the repo root:

Rscript code/run_all.R
Script Output
01_extract_features.R merged city table from shapefile + rasters + CHELSA
02_select_k.R elbow and stability sweeps; data-driven k per dataset
03_clustering.R cluster assignments, distance / mean / region tables
04_figures.R maps, PCA biplots, fingerprints, stability figures
05_tables.R qualitative cluster-summary tables
06_additions.R descriptions, outlier sensitivity, nearest city, resolution check

How k is chosen

02_select_k.R sweeps k = 2..20 for each dataset and records mean baseline and jackknife stability plus within-cluster SS. choose_k() takes the k with the highest jackknife stability (k >= 4 to avoid trivially small solutions, near-ties broken toward the smaller k); the elbow point is reported alongside for cross-checking. Both go into results/tables/selected_k.csv.

Dependencies

here, terra, sf, rpaleoclim, ggplot2, patchwork, maps. Base R for the analysis itself.

Resolution congruence

To compare two resolutions, run the pipeline at RES = "30s", save the merged table as data/cities_merged_5m.rds from a "5m" run, and 06_additions.R reports the agreement between the two combined cluster assignments.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages