{"spec_id":"violin-box","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' violin-box: Violin Plot with Embedded Box Plot\n#' Library: ggplot2 3.5.1 | R 4.4.1\n#' Quality: 91/100 | Created: 2026-09-09\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_PALETTE <- c(\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\",\n                     \"#AE3030\", \"#2ABCCD\", \"#954477\", \"#99B314\")\n\n# --- Data ---------------------------------------------------------------\n# Resting heart rate (bpm) across three training regimens\ndf <- bind_rows(\n  tibble::tibble(group = \"Sedentary\",   value = rnorm(150, mean = 74, sd = 7)),\n  tibble::tibble(group = \"Recreational\", value = rnorm(150, mean = 65, sd = 6)),\n  tibble::tibble(group = \"Endurance\",   value = rnorm(150, mean = 54, sd = 5))\n) %>%\n  mutate(group = factor(group, levels = c(\"Sedentary\", \"Recreational\", \"Endurance\")))\n\ntitle_text <- \"violin-box · r · ggplot2 · anyplot.ai\"\n\n# --- Plot -----------------------------------------------------------------\np <- ggplot(df, aes(x = group, y = value, fill = group)) +\n  geom_violin(color = INK_SOFT, linewidth = 0.35, width = 0.9, trim = FALSE) +\n  geom_boxplot(width = 0.14, color = INK, fill = PAGE_BG,\n               outlier.color = INK_SOFT, outlier.size = 3.2,\n               linewidth = 0.5) +\n  stat_summary(fun = mean, geom = \"point\", shape = 23, size = 3,\n               color = INK, fill = PAGE_BG, stroke = 0.6) +\n  scale_fill_manual(values = IMPRINT_PALETTE) +\n  labs(\n    title = title_text,\n    x = \"Training Regimen\",\n    y = \"Resting Heart Rate (bpm)\"\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, linewidth = 0.15),\n    axis.title        = element_text(color = INK, size = 10),\n    axis.text         = element_text(color = INK_SOFT, size = 8),\n    axis.ticks        = element_blank(),\n    plot.title        = element_text(color = INK, size = 12),\n    legend.position   = \"none\"\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"}