{"spec_id":"violin-swarm","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' violin-swarm: Violin Plot with Overlaid Swarm Points\n#' Library: ggplot2 3.5.1 | R 4.4.1\n#' Quality: 88/100 | Created: 2026-05-18\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\"\nINK         <- if (THEME == \"light\") \"#1A1A17\" else \"#F0EFE8\"\nINK_SOFT    <- if (THEME == \"light\") \"#4A4A44\" else \"#B8B7B0\"\nIMPRINT   <- c(\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\",\n                 \"#AE3030\", \"#2ABCCD\", \"#954477\")\n\n# --- Data -------------------------------------------------------------------\ndf <- tibble::tibble(\n  condition = rep(c(\"Control\", \"Treatment A\", \"Treatment B\", \"Treatment C\"),\n                  each = 60),\n  reaction_time = c(\n    rnorm(60, mean = 350, sd = 50),\n    rnorm(60, mean = 320, sd = 45),\n    rnorm(60, mean = 300, sd = 55),\n    rnorm(60, mean = 310, sd = 48)\n  )\n)\n\n# --- Plot -------------------------------------------------------------------\np <- ggplot(df, aes(x = condition, y = reaction_time)) +\n  geom_violin(\n    fill = IMPRINT[1],\n    alpha = 0.4,\n    color = INK_SOFT,\n    linewidth = 0.8\n  ) +\n  geom_jitter(\n    color = IMPRINT[1],\n    size = 2.5,\n    alpha = 0.7,\n    width = 0.2,\n    height = 0\n  ) +\n  labs(\n    title = \"violin-swarm · R · ggplot2 · anyplot.ai\",\n    x = \"Experimental Condition\",\n    y = \"Reaction Time (ms)\"\n  ) +\n  theme_minimal(base_size = 14) +\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.major.y = element_line(color = INK, linewidth = 0.3),\n    panel.grid.minor = element_blank(),\n    axis.title       = element_text(color = INK, size = 20),\n    axis.text        = element_text(color = INK_SOFT, size = 16),\n    plot.title       = element_text(color = INK, size = 24)\n  )\n\n# --- Save -------------------------------------------------------------------\nggsave(\n  filename = sprintf(\"plot-%s.png\", THEME),\n  plot     = p,\n  device   = ragg::agg_png,\n  width    = 16,\n  height   = 9,\n  units    = \"in\",\n  dpi      = 300\n)\n"}