{"spec_id":"bump-basic","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' bump-basic: Basic Bump Chart\n#' Library: ggplot2 4.0.3 | R 4.6.1\n#' Quality: 85/100 | Updated: 2026-11-27\n\nlibrary(ggplot2)\nlibrary(ragg)\n\n# Theme tokens (Imprint palette, theme-adaptive chrome)\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        <- alpha(INK, 0.15)\n\n# Imprint palette (canonical order)\nIMPRINT_PALETTE <- c(\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\",\n                     \"#AE3030\", \"#2ABCCD\", \"#954477\", \"#99B314\")\n\n# Columns: set these to your table's column names\nRACE   <- \"Race round\"             # role: period\nDRIVER <- \"Driver\"                 # role: entity\nRANK   <- \"Championship position\"  # role: rank\n\n# Data: F1 championship standings over 8 rounds; replace with your own table\nset.seed(42)\ndrivers <- c(\"Hamilton\", \"Verstappen\", \"Leclerc\", \"Norris\", \"Russell\", \"Perez\")\ndf <- tibble::tibble(\n  !!RACE   := rep(1:8, each = 6),\n  !!DRIVER := factor(rep(drivers, times = 8), levels = drivers),\n  !!RANK   := c(\n    2, 1, 3, 5, 4, 6,\n    1, 2, 3, 5, 4, 6,\n    1, 2, 4, 3, 5, 6,\n    2, 1, 4, 3, 5, 6,\n    2, 1, 3, 4, 5, 6,\n    2, 1, 3, 4, 6, 5,\n    1, 2, 3, 4, 6, 5,\n    1, 2, 3, 5, 6, 4\n  )\n)\n\n# Plot: reads only df and the constants above\nn_races    <- max(df[[RACE]])\nn_ranks    <- max(df[[RANK]])\nlabels_end <- df[df[[RACE]] == n_races, ]\n\np <- ggplot(df, aes(x = .data[[RACE]], y = .data[[RANK]],\n                    color = .data[[DRIVER]], group = .data[[DRIVER]])) +\n  geom_line(linewidth = 1.4, lineend = \"round\", linejoin = \"round\") +\n  geom_point(size = 3.5) +\n  geom_text(\n    data     = labels_end,\n    aes(x = .data[[RACE]] + 0.3, label = .data[[DRIVER]]),\n    hjust    = 0,\n    size     = 4.2,\n    fontface = \"bold\"\n  ) +\n  scale_y_reverse(\n    breaks = seq_len(n_ranks),\n    labels = \\(r) paste0(r, c(\"st\", \"nd\", \"rd\", rep(\"th\", 7))[r]),\n    expand = expansion(add = 0.4)\n  ) +\n  scale_x_continuous(\n    breaks = seq_len(n_races),\n    labels = \\(b) paste0(\"R\", b),\n    expand = expansion(mult = c(0.03, 0.22))\n  ) +\n  scale_color_manual(values = IMPRINT_PALETTE) +\n  labs(\n    title = \"bump-basic · r · ggplot2 · anyplot.ai\",\n    x     = RACE,\n    y     = RANK\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.y = element_line(color = GRID, linewidth = 0.3),\n    panel.grid.major.x = element_blank(),\n    panel.grid.minor   = element_blank(),\n    axis.title         = element_text(color = INK, size = 10),\n    axis.text          = element_text(color = INK_SOFT, size = 8),\n    axis.line.x        = element_line(color = INK_SOFT, linewidth = 0.3),\n    plot.title         = element_text(color = INK, size = 12, face = \"bold\"),\n    legend.position    = \"none\",\n    plot.margin        = margin(t = 18, r = 24, b = 18, l = 12, unit = \"pt\")\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"}