{"spec_id":"scatter-basic","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' scatter-basic: Basic Scatter Plot\n#' Library: ggplot2 3.5.1 | R 4.4.1\n#' Quality: 90/100 | Updated: 2026-06-25\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\"\n# Approximate RULE (15% opacity INK blended over PAGE_BG) — ggplot2 lacks rgba\nGRID_LINE   <- if (THEME == \"light\") \"#D8D7D0\" else \"#3A3A36\"\n\n# Imprint palette — canonical order\nIMPRINT_PALETTE <- c(\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\",\n                     \"#AE3030\", \"#2ABCCD\", \"#954477\", \"#99B314\")\n\n# Data — marketing spend vs quarterly revenue across 200 campaigns\nn       <- 200\nspend   <- runif(n, 5, 150)\nrevenue <- 3.5 * spend + 80 + rnorm(n, 0, 150)\nrevenue <- pmax(revenue, 10)\n\ndf <- data.frame(spend = spend, revenue = revenue)\n\n# Pearson r for bottom-right annotation\nr_val   <- cor(df$spend, df$revenue)\nr_label <- sprintf(\"Pearson r = %.2f\", round(r_val, 2))\n\n# Plot\np <- ggplot(df, aes(x = spend, y = revenue)) +\n  geom_smooth(\n    method    = \"lm\",\n    se        = TRUE,\n    color     = IMPRINT_PALETTE[1],\n    fill      = IMPRINT_PALETTE[1],\n    alpha     = 0.15,\n    linewidth = 1.0\n  ) +\n  geom_point(\n    color = IMPRINT_PALETTE[1],\n    size  = 2.5,\n    alpha = 0.7,\n    shape = 16\n  ) +\n  annotate(\n    geom     = \"text\",\n    x        = max(df$spend),\n    y        = min(df$revenue) + 5,\n    label    = r_label,\n    color    = INK_SOFT,\n    size     = 3,\n    fontface = \"italic\",\n    hjust    = 1\n  ) +\n  labs(\n    title = \"scatter-basic · r · ggplot2 · anyplot.ai\",\n    x     = \"Marketing Spend ($K)\",\n    y     = \"Quarterly Revenue ($K)\"\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_LINE, linewidth = 0.3),\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        = element_line(color = INK_SOFT, linewidth = 0.5),\n    axis.ticks       = element_blank(),\n    plot.title       = element_text(color = INK,      size = 12,\n                                    face = \"bold\", margin = margin(b = 12)),\n    plot.margin      = margin(20, 20, 20, 20)\n  )\n\n# Save — 3200×1800 px (landscape 16:9)\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"}