{"spec_id":"rug-basic","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' rug-basic: Basic Rug Plot\n#' Library: ggplot2 3.5.1 | R 4.4.1\n#' Quality: 86/100 | Created: 2026-07-25\n\nlibrary(ggplot2)\nlibrary(tibble)\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\"\nINK_FAINT <- if (THEME == \"light\") \"#1A1A1726\" else \"#F0EFE826\"  # INK at ~15% alpha, for gridlines\n\nIMPRINT_PALETTE <- c(\n  \"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\",\n  \"#AE3030\", \"#2ABCCD\", \"#954477\", \"#99B314\"\n)\nBRAND <- IMPRINT_PALETTE[1]\n\n# --- Data -----------------------------------------------------------------\n# Reaction times from a cognitive test: a fast, practiced group and a\n# slower, hesitant group combine into a bimodal distribution. The rug\n# marks reveal that clustering directly, something the smooth density\n# curve alone would blur into a single wide hump.\nreaction_ms <- c(\n  rnorm(85, mean = 380, sd = 40),\n  rnorm(55, mean = 620, sd = 70)\n)\ndf <- tibble(reaction_ms = reaction_ms)\n\n# --- Plot -------------------------------------------------------------------\np <- ggplot(df, aes(x = reaction_ms)) +\n  geom_density(fill = BRAND, color = BRAND, alpha = 0.25, linewidth = 1.0) +\n  geom_rug(\n    sides     = \"b\",\n    color     = BRAND,\n    alpha     = 0.3,\n    linewidth = 0.6,\n    length    = unit(0.035, \"npc\")\n  ) +\n  labs(\n    title = \"rug-basic · r · ggplot2 · anyplot.ai\",\n    x     = \"Reaction Time (ms)\",\n    y     = \"Density\"\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.x  = element_blank(),\n    panel.grid.minor    = element_blank(),\n    panel.grid.major.y  = element_line(color = INK_FAINT, linewidth = 0.2),\n    axis.line           = element_line(color = INK_SOFT, linewidth = 0.4),\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),\n    plot.margin         = margin(t = 12, 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"}