{"spec_id":"scatter-map-geographic","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' scatter-map-geographic: Scatter Map with Geographic Points\n#' Library: ggplot2 3.5.1 | R 4.4.1\n#' Quality: 92/100 | Created: 2026-05-18\n\nlibrary(ggplot2)\nlibrary(dplyr)\nlibrary(scales)\nlibrary(ragg)\n\nset.seed(42)\n\n# --- Theme tokens -----------------------------------------------------------\nTHEME       <- Sys.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG     <- if (THEME == \"light\") \"#FAF8F1\" else \"#1A1A17\"\nINK         <- if (THEME == \"light\") \"#1A1A17\" else \"#F0EFE8\"\nINK_SOFT    <- if (THEME == \"light\") \"#4A4A44\" else \"#B8B7B0\"\nGRID_COLOR  <- if (THEME == \"light\") scales::alpha(\"#1A1A17\", 0.08) else scales::alpha(\"#F0EFE8\", 0.08)\nIMPRINT   <- c(\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\",\n                 \"#AE3030\", \"#2ABCCD\", \"#954477\")\n\n# --- Data: Earthquake epicenters with magnitude and depth -------------------\nearthquakes <- tibble::tibble(\n  longitude = c(-122.4, -118.2, -155.6, -73.0, 139.4, 146.6, 174.9, 120.5,\n                 -71.2, -77.0, 102.8, 121.8, 172.5, -80.8, 91.3,\n                 -122.7, -118.5, -155.3, -73.1, 139.5),\n  latitude = c(37.9, 34.0, 19.4, 40.8, 36.1, -39.0, -41.3, 0.8,\n               -17.0, -12.0, 3.3, 14.2, -16.7, 17.4, 28.0,\n               37.8, 34.1, 19.5, 40.7, 36.2),\n  magnitude = c(4.1, 3.8, 4.5, 3.2, 4.3, 4.7, 4.2, 3.9,\n                3.6, 4.0, 3.7, 3.5, 4.4, 3.3, 4.6,\n                3.9, 4.2, 4.0, 3.4, 4.5),\n  depth_km = c(12, 8, 15, 5, 18, 25, 30, 10,\n               7, 20, 12, 8, 35, 6, 40,\n               10, 9, 14, 6, 17)\n)\n\n# --- Plot -------------------------------------------------------------------\nanyplot_theme <- theme_minimal(base_size = 14) +\n  theme(\n    plot.background   = element_rect(fill = PAGE_BG, color = PAGE_BG),\n    panel.background  = element_rect(fill = PAGE_BG, color = NA),\n    panel.grid.major  = element_line(color = GRID_COLOR, linewidth = 0.2),\n    panel.grid.minor  = element_blank(),\n    axis.title        = element_text(color = INK, size = 20),\n    axis.text         = element_text(color = INK_SOFT, size = 16),\n    plot.title        = element_text(color = INK, size = 24, face = \"plain\"),\n    legend.background = element_rect(fill = PAGE_BG, color = NA),\n    legend.text       = element_text(color = INK_SOFT, size = 16),\n    legend.title      = element_text(color = INK, size = 18),\n    panel.border      = element_blank()\n  )\n\np <- ggplot(earthquakes, aes(x = longitude, y = latitude)) +\n  geom_point(aes(size = magnitude, color = depth_km), alpha = 0.75) +\n  scale_size_continuous(name = \"Magnitude\", range = c(2, 12)) +\n  scale_color_viridis_c(name = \"Depth (km)\", option = \"viridis\") +\n  labs(\n    title = \"scatter-map-geographic · r · ggplot2 · anyplot.ai\",\n    x = \"Longitude\",\n    y = \"Latitude\"\n  ) +\n  coord_fixed(ratio = 1.3) +\n  anyplot_theme\n\n# --- Save -------------------------------------------------------------------\nggsave(\n  filename = sprintf(\"plot-%s.png\", THEME),\n  plot     = p,\n  device   = ragg::agg_png,\n  width    = 16,\n  height   = 9,\n  units    = \"in\",\n  dpi      = 300\n)\n"}