{"spec_id":"line-timeseries","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' line-timeseries: Time Series Line Plot\n#' Library: ggplot2 4.0.3 | R 4.6.1\n#' Quality: 83/100 | Updated: 2026-10-29\n\nlibrary(ggplot2)\nlibrary(scales)\nlibrary(ragg)\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\nMUTED    <- if (THEME == \"light\") \"#6B6A63\" else \"#A8A79F\"  # Imprint muted anchor — trend line\nIMPRINT_PALETTE <- c(\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\",\n                     \"#AE3030\", \"#2ABCCD\", \"#954477\", \"#99B314\")  # Imprint palette\n\n# --- Columns: set these to your table's column names -------------------------\nDATE        <- \"Date\"                       # role: x (date)\nTEMPERATURE <- \"Outdoor Temperature (°C)\"   # role: y (value)\n\n# --- Data: replace this block with your own table, for example\n# df <- read.csv(\"temperature.csv\", check.names = FALSE); df[[DATE]] <- as.Date(df[[DATE]])\n# Six months of daily outdoor temperature readings with a seasonal warm-up\n# trend, weekly wobble, and day-to-day sensor noise.\nset.seed(42)\nn_days <- 182\nday_idx <- seq_len(n_days)\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)\n\ndf <- tibble::tibble(\n  !!DATE        := seq(as.Date(\"2024-01-01\"), by = \"day\", length.out = n_days),\n  !!TEMPERATURE := seasonal_trend + weekly_wobble + sensor_noise\n)\n\n# --- Plot: reads only df and the constants above ----------------------------\np <- ggplot(df, aes(x = .data[[DATE]], y = .data[[TEMPERATURE]])) +\n  geom_smooth(\n    method = \"loess\", span = 0.3, se = FALSE,\n    color = MUTED, linewidth = 0.8, linetype = \"dashed\"\n  ) +\n  geom_line(color = IMPRINT_PALETTE[1], 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 = \"line-timeseries · r · ggplot2 · anyplot.ai\",\n    x = DATE,\n    y = TEMPERATURE\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    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"}