{"spec_id":"band-basic","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' band-basic: Basic Band Plot\n#' Library: ggplot2 3.5.1 | R 4.4.1\n#' Quality: 87/100 | Created: 2026-05-29\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\"\nINK_MUTED   <- if (THEME == \"light\") \"#6B6A63\" else \"#A8A79F\"\n\nIMPRINT_PALETTE <- c(\n    \"#009E73\",  # 1 — brand green\n    \"#C475FD\", \"#4467A3\", \"#BD8233\",\n    \"#AE3030\", \"#2ABCCD\", \"#954477\", \"#99B314\"\n)\n\n# Data — 60-month temperature forecast with widening 95% CI\nmonths    <- seq_len(60)\nbase_temp <- 13.5 + 0.03 * months + 7.5 * sin(2 * pi * (months - 3) / 12)\nnoise     <- rnorm(60, sd = 0.35)\ny_center  <- base_temp + noise\nband_half <- 1.0 + 0.018 * months  # uncertainty grows with forecast horizon\ny_lower   <- y_center - band_half\ny_upper   <- y_center + band_half\n\ndf <- data.frame(\n    month    = months,\n    y_center = y_center,\n    y_lower  = y_lower,\n    y_upper  = y_upper\n)\n\n# Annotation: sits above the band at the Year 4 winter trough (month 48)\n# where vertical space is available, pointing toward the widening right side\nann_x <- 48\nann_y <- df$y_upper[48] + 0.6\n\np <- ggplot(df, aes(x = month)) +\n    geom_ribbon(\n        aes(ymin = y_lower, ymax = y_upper, fill = \"95% CI\"),\n        alpha = 0.35,\n        color = NA\n    ) +\n    geom_line(\n        aes(y = y_center, color = \"Central Forecast\"),\n        linewidth = 1.2\n    ) +\n    annotate(\n        \"text\",\n        x     = ann_x,\n        y     = ann_y,\n        label = \"uncertainty widens →\",\n        color = INK_MUTED,\n        size  = 2.6,\n        hjust = 0,\n        vjust = 0\n    ) +\n    scale_fill_manual(\n        values = c(\"95% CI\" = IMPRINT_PALETTE[1]),\n        guide  = guide_legend(override.aes = list(alpha = 0.5))\n    ) +\n    scale_color_manual(\n        values = c(\"Central Forecast\" = IMPRINT_PALETTE[3]),\n        guide  = guide_legend(override.aes = list(linewidth = 1.5))\n    ) +\n    scale_x_continuous(\n        breaks = c(1, 13, 25, 37, 49),\n        labels = paste0(\"Year \", 1:5)\n    ) +\n    labs(\n        x        = \"Forecast Horizon\",\n        y        = \"Temperature (°C)\",\n        title    = \"band-basic · r · ggplot2 · anyplot.ai\",\n        subtitle = \"Seasonal temperature forecast with widening 95% confidence interval\",\n        fill     = NULL,\n        color    = NULL\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 = INK_SOFT, linewidth = 0.25),\n        panel.grid.major.x = element_blank(),\n        panel.grid.minor   = element_blank(),\n        panel.border       = element_blank(),\n        axis.title         = element_text(color = INK,      size = 10),\n        axis.text          = element_text(color = INK_SOFT, size = 8),\n        axis.line          = element_line(color = INK_SOFT, linewidth = 0.4),\n        plot.title         = element_text(color = INK,      size = 12),\n        plot.subtitle      = element_text(color = INK_SOFT, size = 9,\n                                          margin = margin(b = 8)),\n        legend.position      = \"top\",\n        legend.justification = \"left\",\n        legend.background    = element_rect(fill = ELEVATED_BG, color = NA),\n        legend.text          = element_text(color = INK_SOFT, size = 8),\n        legend.margin        = margin(2, 4, 2, 4),\n        legend.key.size      = unit(0.8, \"lines\"),\n        legend.spacing.x     = unit(0.3, \"cm\"),\n        plot.margin          = margin(16, 20, 12, 12)\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"}