{"spec_id":"line-parametric","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' line-parametric: Parametric Curve Plot\n#' Library: ggplot2 3.5.1 | R 4.4.1\n#' Quality: 90/100 | Created: 2026-06-20\n\nlibrary(ggplot2)\nlibrary(dplyr)\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\nIMPRINT_PALETTE <- c(\n  \"#009E73\",  # 1 — brand green (first series)\n  \"#C475FD\",  # 2 — lavender\n  \"#4467A3\",  # 3 — blue\n  \"#BD8233\",  # 4 — ochre\n  \"#AE3030\",  # 5 — matte red\n  \"#2ABCCD\",  # 6 — cyan\n  \"#954477\",  # 7 — rose\n  \"#99B314\"   # 8 — lime\n)\n\n# Data\nn <- 1200\n\n# Lissajous figure: x = sin(3t), y = sin(2t) for t in [0, 2pi]\nt_liss  <- seq(0, 2 * pi, length.out = n)\ndf_liss <- data.frame(\n  t_norm = (t_liss - min(t_liss)) / diff(range(t_liss)),\n  x      = sin(3 * t_liss),\n  y      = sin(2 * t_liss),\n  curve  = \"Lissajous (3:2)\"\n)\n\n# Archimedean spiral: x = t*cos(t), y = t*sin(t) for t in [0, 4pi]\nt_sprl  <- seq(0, 4 * pi, length.out = n)\ndf_sprl <- data.frame(\n  t_norm = (t_sprl - min(t_sprl)) / diff(range(t_sprl)),\n  x      = t_sprl * cos(t_sprl),\n  y      = t_sprl * sin(t_sprl),\n  curve  = \"Archimedean Spiral\"\n)\n\ndf <- rbind(df_liss, df_sprl)\ndf$curve <- factor(df$curve, levels = c(\"Lissajous (3:2)\", \"Archimedean Spiral\"))\n\n# Start and end markers per curve\nstart_pts <- df %>% group_by(curve) %>% slice(1)   %>% ungroup()\nend_pts   <- df %>% group_by(curve) %>% slice(n()) %>% ungroup()\n\n# Plot\np <- ggplot(df, aes(x = x, y = y, color = t_norm)) +\n  geom_path(linewidth = 0.9) +\n  geom_point(\n    data = start_pts,\n    aes(x = x, y = y),\n    inherit.aes = FALSE,\n    color = IMPRINT_PALETTE[1],\n    size  = 3.5,\n    shape = 19\n  ) +\n  geom_point(\n    data = end_pts,\n    aes(x = x, y = y),\n    inherit.aes = FALSE,\n    color = IMPRINT_PALETTE[3],\n    size  = 3.5,\n    shape = 15\n  ) +\n  scale_color_gradient(\n    low  = \"#009E73\",\n    high = \"#4467A3\",\n    name = \"t (0 to 1)\"\n  ) +\n  facet_wrap(~curve, scales = \"free\") +\n  labs(\n    title   = \"line-parametric · r · ggplot2 · anyplot.ai\",\n    x       = \"x(t)\",\n    y       = \"y(t)\",\n    caption = \"● start (t = 0)    ■ end (t = max)\"\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(\n      color     = adjustcolor(INK, alpha.f = 0.12),\n      linewidth = 0.3\n    ),\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                                     margin = margin(b = 10)),\n    plot.caption      = element_text(color = INK_SOFT, size = 8,\n                                     hjust = 0, margin = margin(t = 8)),\n    legend.background = element_rect(fill = ELEVATED_BG, color = INK_SOFT,\n                                      linewidth = 0.3),\n    legend.text       = element_text(color = INK_SOFT, size = 8),\n    legend.title      = element_text(color = INK,      size = 10),\n    legend.key.width  = unit(1.2, \"cm\"),\n    strip.text        = element_text(color = INK, size = 10, face = \"bold\",\n                                     margin = margin(b = 6)),\n    strip.background  = element_blank(),\n    aspect.ratio      = 1\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"}