{"spec_id":"violin-box","library":"makie","language":"julia","code":"# anyplot.ai\n# violin-box: Violin Plot with Embedded Box Plot\n# Library: makie 0.21.9 | Julia 1.11.9\n# Quality: 88/100 | Created: 2026-09-09\n\nusing CairoMakie\nusing Colors\nusing Random\n\nRandom.seed!(42)\n\n# --- Theme tokens -----------------------------------------------------------\nconst THEME       = get(ENV, \"ANYPLOT_THEME\", \"light\")\nconst PAGE_BG      = THEME == \"light\" ? colorant\"#FAF8F1\" : colorant\"#1A1A17\"\nconst ELEVATED_BG  = THEME == \"light\" ? colorant\"#FFFDF6\" : colorant\"#242420\"\nconst INK          = THEME == \"light\" ? colorant\"#1A1A17\" : colorant\"#F0EFE8\"\nconst INK_SOFT     = THEME == \"light\" ? colorant\"#4A4A44\" : colorant\"#B8B7B0\"\nconst GRID_COLOR   = RGBAf(INK.r, INK.g, INK.b, 0.15)\n\n# Imprint categorical palette — first series is ALWAYS brand green\nconst IMPRINT_PALETTE = [\n    colorant\"#009E73\",  # 1 — Control\n    colorant\"#C475FD\",  # 2 — Mild Stress\n    colorant\"#4467A3\",  # 3 — High Stress\n]\n\n# --- Data ---------------------------------------------------------------\n# Salivary cortisol response (ng/mL) under three lab-controlled stress conditions\ngroups = [\"Control\", \"Mild Stress\", \"High Stress\"]\nn_per_group = 150\ngroup_means = [8.5, 12.0, 17.5]\ngroup_sds = [1.8, 2.6, 3.4]\n\ngroup_index = Int[]\ncortisol_level = Float64[]\nfor (i, (mean_level, sd_level)) in enumerate(zip(group_means, group_sds))\n    append!(group_index, fill(i, n_per_group))\n    append!(cortisol_level, mean_level .+ sd_level .* randn(n_per_group))\n    # A couple of real physiological outliers per group (hyper- / non-responders)\n    append!(group_index, fill(i, 2))\n    append!(cortisol_level, [mean_level + 4.2 * sd_level, mean_level - 3.4 * sd_level])\nend\nviolin_colors = [IMPRINT_PALETTE[i] for i in group_index]\n\n# --- Plot -----------------------------------------------------------------\ntitle_text = \"Cortisol Response by Stress Condition · violin-box · julia · makie · anyplot.ai\"\n\nfig = Figure(size = (1600, 900), fontsize = 14, backgroundcolor = PAGE_BG)\n\nax = Axis(\n    fig[1, 1];\n    title             = title_text,\n    titlesize         = 21,\n    titlecolor        = INK,\n    xlabel            = \"Stress Test Condition\",\n    ylabel            = \"Cortisol Level (ng/mL)\",\n    xlabelsize        = 14,\n    ylabelsize        = 14,\n    xlabelcolor       = INK,\n    ylabelcolor       = INK,\n    xticks            = (1:3, groups),\n    xticklabelsize    = 12,\n    yticklabelsize    = 12,\n    xticklabelcolor   = INK_SOFT,\n    yticklabelcolor   = INK_SOFT,\n    backgroundcolor   = PAGE_BG,\n    topspinevisible   = false,\n    rightspinevisible = false,\n    leftspinecolor    = INK_SOFT,\n    bottomspinecolor  = INK_SOFT,\n    xgridvisible      = false,\n    ygridcolor        = GRID_COLOR,\n    yminorgridvisible = false,\n)\n\nviolin!(\n    ax, group_index, cortisol_level;\n    color = violin_colors, strokecolor = INK, strokewidth = 1.5,\n    width = 0.75, show_median = false,\n)\nboxplot!(\n    ax, group_index, cortisol_level;\n    width = 0.16, color = ELEVATED_BG, strokecolor = INK, strokewidth = 1.2,\n    mediancolor = INK, medianlinewidth = 2.5,\n    whiskercolor = INK, whiskerwidth = 0.5, whiskerlinewidth = 1.5,\n    show_notch = true, notchwidth = 0.6,\n    outliercolor = INK, outlierstrokecolor = PAGE_BG, outlierstrokewidth = 1.2,\n    markersize = 10, show_outliers = true,\n)\n\n# --- Save -------------------------------------------------------------------\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}