{"spec_id":"dumbbell-basic","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' dumbbell-basic: Basic Dumbbell Chart\n#' Library: ggplot2 3.5.1 | R 4.4.1\n#' Quality: 90/100 | Created: 2026-06-30\n\nlibrary(ggplot2)\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\"\nGRID_COLOR  <- adjustcolor(INK, alpha.f = 0.12)\n\n# Imprint palette (hybrid-v3 sort order)\nIMPRINT_PALETTE <- c(\n  \"#009E73\",  # 1 — brand green → Before score\n  \"#C475FD\",  # 2 — lavender    → After score\n  \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\", \"#954477\", \"#99B314\"\n)\n\n# Data: department wellness scores before and after a workplace initiative\ndepartments <- c(\"Engineering\", \"Marketing\", \"Finance\", \"Operations\",\n                 \"Research\", \"Sales\", \"HR\", \"Product\", \"Design\", \"Support\")\nbefore <- c(62, 71, 58, 74, 68, 79, 65, 72, 67, 75)\nafter  <- c(78, 83, 71, 81, 84, 88, 76, 85, 79, 82)\n\ndf <- data.frame(\n  department = departments,\n  before     = before,\n  after      = after,\n  diff       = after - before\n)\n\n# Sort by improvement so largest gains appear at the top\ndf            <- df[order(df$diff), ]\ndf$department <- factor(df$department, levels = df$department)\n\n# Plot\np <- ggplot(df) +\n  geom_segment(\n    aes(x = before, xend = after, y = department, yend = department),\n    color     = INK_SOFT,\n    linewidth = 0.7,\n    alpha     = 0.5\n  ) +\n  geom_point(\n    aes(x = before, y = department, color = \"Before\"),\n    size = 3.5\n  ) +\n  geom_point(\n    aes(x = after, y = department, color = \"After\"),\n    size = 3.5\n  ) +\n  scale_color_manual(\n    values = c(\"Before\" = IMPRINT_PALETTE[1], \"After\" = IMPRINT_PALETTE[2]),\n    breaks = c(\"Before\", \"After\"),\n    name   = NULL\n  ) +\n  scale_x_continuous(\n    expand = expansion(mult = 0.05)\n  ) +\n  labs(\n    x     = \"Wellness Score\",\n    y     = NULL,\n    title = \"dumbbell-basic · r · ggplot2 · anyplot.ai\"\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_line(color = GRID_COLOR, linewidth = 0.4),\n    panel.grid.major.y = element_blank(),\n    panel.grid.minor   = element_blank(),\n    panel.border       = element_blank(),\n    axis.line.x        = element_line(color = INK_SOFT,   linewidth = 0.5),\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,\n                                      margin = margin(b = 16)),\n    plot.margin        = margin(t = 20, r = 24, b = 16, l = 16),\n    legend.position    = \"top\",\n    legend.justification = \"left\",\n    legend.background  = element_rect(fill = ELEVATED_BG, color = NA),\n    legend.text        = element_text(color = INK_SOFT,   size = 8),\n    legend.key         = element_rect(fill = NA,           color = NA),\n    legend.margin      = margin(b = 4)\n  ) +\n  guides(color = guide_legend(override.aes = list(size = 4)))\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"}