{"spec_id":"map-route-path","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' map-route-path: Route Path Map\n#' Library: ggplot2 3.5.1 | R 4.4.1\n#' Quality: 85/100 | Created: 2026-05-21\n\nlibrary(ggplot2)\nlibrary(ragg)\n\nset.seed(42)\n\n# Theme tokens\nTHEME       <- Sys.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG     <- if (THEME == \"light\") \"#FAF8F1\" else \"#1A1A17\"\nELEVATED_BG <- if (THEME == \"light\") \"#FFFDF6\" else \"#242420\"\nINK         <- if (THEME == \"light\") \"#1A1A17\" else \"#F0EFE8\"\nINK_SOFT    <- if (THEME == \"light\") \"#4A4A44\" else \"#B8B7B0\"\nIMPRINT   <- c(\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\",\n                 \"#AE3030\", \"#2ABCCD\", \"#954477\")\nGRID_COLOR  <- if (THEME == \"light\") INK_SOFT else \"#3A3A36\"\n\n# Data: Synthetic GPS track for a mountain trail in Colorado Rockies\nn_points <- 200\nt        <- seq(0, 2 * pi, length.out = n_points)\n\nlon <- -105.6500 +\n  0.085 * (t / (2 * pi)) +\n  0.011 * sin(t * 2.5) +\n  rnorm(n_points, 0, 0.0005)\n\nlat <- 40.4100 +\n  0.018 * sin(t * 1.1) +\n  0.007 * cos(t * 3.5) +\n  rnorm(n_points, 0, 0.0005)\n\n# Elevation: classic ascent-peak-descent profile with realistic GPS noise\nelevation <- 3100 +\n  600 * sin(seq(0, pi, length.out = n_points)) +\n  85  * sin(seq(0, 8 * pi, length.out = n_points)) +\n  rnorm(n_points, 0, 22)\n\ndf <- tibble::tibble(\n  lon       = lon,\n  lat       = lat,\n  sequence  = seq_len(n_points),\n  elevation = elevation\n)\n\n# Endpoint markers (start = circle, end = square)\nendpoints <- tibble::tibble(\n  lon  = c(df$lon[1], df$lon[n_points]),\n  lat  = c(df$lat[1], df$lat[n_points]),\n  role = factor(c(\"Start\", \"End\"), levels = c(\"Start\", \"End\"))\n)\n\n# Plot\np <- ggplot(df, aes(x = lon, y = lat)) +\n  geom_path(\n    aes(color = elevation),\n    linewidth = 2.0,\n    lineend   = \"round\",\n    linejoin  = \"round\"\n  ) +\n  geom_point(\n    data   = endpoints,\n    aes(shape = role, fill = role),\n    size   = 6.5,\n    color  = PAGE_BG,\n    stroke = 1.8\n  ) +\n  scale_color_viridis_c(\n    option = \"viridis\",\n    name   = \"Elevation (m)\",\n    guide  = guide_colorbar(\n      barwidth       = 0.6,\n      barheight      = 7,\n      title.position = \"top\"\n    )\n  ) +\n  scale_fill_manual(\n    values = c(\"Start\" = IMPRINT[1], \"End\" = IMPRINT[2]),\n    name   = NULL\n  ) +\n  scale_shape_manual(\n    values = c(\"Start\" = 21, \"End\" = 22),\n    name   = NULL\n  ) +\n  coord_fixed(ratio = 1.31) +\n  labs(\n    title = \"Rocky Mountain Trail · map-route-path · r · ggplot2 · anyplot.ai\",\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.border      = element_blank(),\n    panel.grid.major  = element_line(color = GRID_COLOR,   linewidth = 0.10),\n    panel.grid.minor  = element_blank(),\n    axis.line         = element_line(color = INK_SOFT,    linewidth = 0.5),\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  = 12),\n    legend.background = element_rect(fill  = ELEVATED_BG, color = INK_SOFT, linewidth = 0.3),\n    legend.text       = element_text(color = INK_SOFT,    size  = 8),\n    legend.title      = element_text(color = INK,         size  = 10),\n    legend.key        = element_rect(fill  = PAGE_BG,     color = NA),\n    legend.margin     = margin(5, 8, 5, 8),\n    plot.margin       = margin(10, 15, 10, 10, unit = \"pt\")\n  )\n\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"}