{"spec_id":"box-basic","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' box-basic: Basic Box Plot\n#' Library: ggplot2 4.0.3 | R 4.6.1\n#' Quality: 84/100 | Updated: 2026-10-29\n\nlibrary(ggplot2)\nlibrary(scales)\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\"\nIMPRINT_PALETTE <- c(\n    \"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\",\n    \"#AE3030\", \"#2ABCCD\", \"#954477\", \"#99B314\"\n)\n\n# --- Columns: set these to your table's column names -----------------------\nDEPARTMENT <- \"Department\"          # role: category\nSALARY     <- \"Annual Salary (USD)\" # role: value\n\n# --- Data: replace this block with your own table, e.g. df <- read.csv(\"salaries.csv\", check.names = FALSE)\nset.seed(42)\ndepartments <- c(\"Engineering\", \"Marketing\", \"Sales\", \"Design\", \"Research\")\ndept_means  <- c(95000, 72000, 78000, 82000, 105000)\ndept_sds    <- c(18000, 12000, 15000, 13000, 20000)\nn_per_dept  <- 80\n\ndf <- tibble::tibble(\n    !!DEPARTMENT := rep(departments, each = n_per_dept),\n    !!SALARY     := unlist(lapply(seq_along(departments), function(i) {\n        rnorm(n_per_dept, mean = dept_means[i], sd = dept_sds[i])\n    }))\n)\n\n# --- Plot: reads only df and the constants above ----------------------------\ndf[[DEPARTMENT]] <- factor(df[[DEPARTMENT]], levels = unique(df[[DEPARTMENT]]))\n\np <- ggplot(df, aes(x = .data[[DEPARTMENT]], y = .data[[SALARY]], fill = .data[[DEPARTMENT]])) +\n    # Whiskers reach 1.5 * IQR; values beyond are drawn as individual outlier points\n    geom_boxplot(\n        color                = INK_SOFT,\n        linewidth            = 0.6,\n        median.linewidth     = 1.4,\n        median.colour        = INK,\n        outlier.size         = 1.6,\n        outlier.alpha        = 0.8,\n        width                = 0.55,\n        alpha                = 0.85\n    ) +\n    scale_fill_manual(values = IMPRINT_PALETTE, guide = \"none\") +\n    scale_y_continuous(\n        labels = label_dollar(scale = 0.001, suffix = \"k\"),\n        expand = expansion(mult = c(0.05, 0.08))\n    ) +\n    labs(\n        title    = \"box-basic · r · ggplot2 · anyplot.ai\",\n        x        = DEPARTMENT,\n        y        = SALARY\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.border       = element_blank(),\n        panel.grid.major.y = element_line(color = INK_SOFT, linewidth = 0.2),\n        panel.grid.major.x = element_blank(),\n        panel.grid.minor   = element_blank(),\n        axis.line.x        = element_line(color = INK_SOFT, linewidth = 0.4),\n        axis.line.y        = 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(\n            color  = INK,\n            size   = 12,\n            margin = margin(b = 10)\n        ),\n        plot.margin = margin(t = 16, r = 20, b = 16, l = 16)\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"}