{"spec_id":"scatter-color-mapped","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' scatter-color-mapped: Color-Mapped Scatter Plot\n#' Library: ggplot2 3.5.1 | R 4.4.1\n#' Quality: 89/100 | Created: 2026-09-05\n\nlibrary(ggplot2)\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\"\nIMPRINT_PALETTE <- c(\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\",\n                     \"#AE3030\", \"#2ABCCD\", \"#954477\", \"#99B314\")\n\n# --- Data ---------------------------------------------------------------\n# Weather-station network: temperature rises toward the south and falls\n# with elevation-like noise, giving the color channel a real spatial signal.\nn_stations <- 320\nlongitude <- runif(n_stations, -9, 9)\nlatitude <- runif(n_stations, 36, 54)\ntemperature_c <- 26 - 0.55 * (latitude - 36) + rnorm(n_stations, 0, 2.2)\n\nstations <- tibble::tibble(longitude, latitude, temperature_c)\n\n# --- Plot -----------------------------------------------------------------\ntitle_text <- \"Weather Station Temperatures · scatter-color-mapped · r · ggplot2 · anyplot.ai\"\ntitle_size <- round(12 * min(1, 67 / nchar(title_text)))\nsubtitle_text <- \"Stations warm up steadily from north to south across the network\"\n\np <- ggplot(stations, aes(x = longitude, y = latitude, color = temperature_c)) +\n  geom_point(size = 2.5, alpha = 0.65) +\n  scale_color_gradient(\n    name = \"Temperature (°C)\",\n    low = IMPRINT_PALETTE[1],\n    high = IMPRINT_PALETTE[3],\n    guide = guide_colorbar(\n      barwidth = 0.6, barheight = 8, ticks.colour = INK, frame.colour = INK_SOFT\n    )\n  ) +\n  labs(\n    title = title_text,\n    subtitle = subtitle_text,\n    x = \"Longitude (°)\",\n    y = \"Latitude (°)\"\n  ) +\n  theme_minimal(base_size = 8) +\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 = alpha(INK, 0.15), linewidth = 0.3),\n    panel.grid.minor  = element_line(color = alpha(INK, 0.08), linewidth = 0.2),\n    axis.title        = element_text(color = INK, size = 10),\n    axis.text         = element_text(color = INK_SOFT, size = 8),\n    plot.title        = element_text(color = INK, size = title_size),\n    plot.subtitle     = element_text(color = INK_SOFT, size = 9),\n    legend.background = element_rect(fill = PAGE_BG, color = NA),\n    legend.title      = element_text(color = INK, size = 10),\n    legend.text       = element_text(color = INK_SOFT, size = 8)\n  )\n\n# --- Save -------------------------------------------------------------------\nggsave(\n  filename = sprintf(\"plot-%s.png\", THEME),\n  plot     = p,\n  device   = ragg::agg_png,\n  width    = 8,\n  height   = 4.5,\n  units    = \"in\",\n  dpi      = 400\n)\n"}