{"spec_id":"line-timeseries","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' line-timeseries: Time Series Line Plot\n#' Library: ggplot2 3.5.1 | R 4.4.1\n#' Quality: 88/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\"\nGRID     <- scales::alpha(INK, 0.15)  # faint grid — element_line has no alpha arg\nBRAND    <- \"#009E73\"  # Imprint palette position 1 — ALWAYS first series\nMUTED    <- if (THEME == \"light\") \"#6B6A63\" else \"#A8A79F\"  # Imprint muted anchor — reference line\n\n# --- Data ---------------------------------------------------------------\n# Six months of daily outdoor temperature readings with a seasonal warm-up\n# trend, weekly wobble, and day-to-day sensor noise.\nn_days <- 182\ndates <- seq(as.Date(\"2024-01-01\"), by = \"day\", length.out = n_days)\nday_idx <- seq_len(n_days)\n\nseasonal_trend <- 4 + 14 * sin(2 * pi * (day_idx - 109) / 365)\nweekly_wobble <- 1.2 * sin(2 * pi * day_idx / 7)\nsensor_noise <- rnorm(n_days, mean = 0, sd = 1.6)\ntemperature_c <- seasonal_trend + weekly_wobble + sensor_noise\n\ndf <- tibble::tibble(date = dates, temperature_c = temperature_c)\n\ntitle_text <- \"line-timeseries · r · ggplot2 · anyplot.ai\"\n\n# --- Plot -----------------------------------------------------------------\np <- ggplot(df, aes(x = date, y = temperature_c)) +\n  geom_smooth(\n    method = \"loess\", span = 0.3, se = FALSE,\n    color = MUTED, linewidth = 0.8, linetype = \"dashed\"\n  ) +\n  geom_line(color = BRAND, linewidth = 2) +\n  scale_x_date(\n    date_breaks = \"1 month\",\n    labels = scales::label_date(\"%b\")\n  ) +\n  scale_y_continuous(labels = scales::label_number(suffix = \"°C\")) +\n  labs(\n    title = title_text,\n    x = \"Date\",\n    y = \"Outdoor Temperature (°C)\"\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 = GRID, linewidth = 0.4),\n    panel.grid.minor  = element_blank(),\n    panel.border      = element_blank(),\n    axis.line         = element_line(color = INK_SOFT, linewidth = 0.4),\n    axis.ticks        = element_blank(),\n    axis.title        = element_text(color = INK, size = 10),\n    axis.text         = element_text(color = INK_SOFT, size = 8),\n    axis.text.x       = element_text(angle = 30, hjust = 1),\n    plot.title        = element_text(color = INK, size = 12, face = \"bold\"),\n    plot.margin       = margin(t = 14, r = 20, b = 10, l = 10)\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"}