{"spec_id":"bar-horizontal","library":"makie","language":"julia","code":"# anyplot.ai\n# bar-horizontal: Horizontal Bar Chart\n# Library: makie 0.21.9 | Julia 1.11.9\n# Quality: 94/100 | Created: 2026-08-05\n\nusing CairoMakie\nusing Colors\n\n# --- Theme tokens -----------------------------------------------------------\nconst THEME    = get(ENV, \"ANYPLOT_THEME\", \"light\")\nconst PAGE_BG  = THEME == \"light\" ? colorant\"#FAF8F1\" : colorant\"#1A1A17\"\nconst INK      = THEME == \"light\" ? colorant\"#1A1A17\" : colorant\"#F0EFE8\"\nconst INK_SOFT = THEME == \"light\" ? colorant\"#4A4A44\" : colorant\"#B8B7B0\"\n\n# Imprint palette position 1 — ALWAYS first (and here only) categorical series\nconst BRAND = colorant\"#009E73\"\n\n# --- Data --------------------------------------------------------------------\n# Most populous countries, 2024 estimate (millions), ranked largest to smallest.\ncountries  = [\"India\", \"China\", \"United States\", \"Indonesia\", \"Pakistan\",\n              \"Nigeria\", \"Brazil\", \"Bangladesh\", \"Russia\", \"Mexico\"]\npopulation = [1441.0, 1425.0, 335.0, 279.0, 240.0, 227.0, 216.0, 173.0, 144.0, 130.0]\nn          = length(countries)\n\n# Reverse so the largest value renders at the top of the y-axis (rank 1 on top).\nplot_countries  = reverse(countries)\nplot_population = reverse(population)\n\n# Focal-point insight for the leading country, used by the subtitle annotation below.\nleader_ratio = round(population[1] / population[end], digits = 1)\n\n# --- Plot ----------------------------------------------------------------------\nfig = Figure(\n    size            = (1600, 900),\n    fontsize        = 14,\n    backgroundcolor = PAGE_BG,\n)\n\n# GridLayout composition: a dedicated subtitle row above the Axis carries the\n# data-driven takeaway — a Makie-native alternative to a plain text annotation.\nLabel(\n    fig[0, 1],\n    \"India leads the ranking with $(leader_ratio)× the population of 10th-ranked Mexico\";\n    fontsize = 13,\n    color    = INK_SOFT,\n    halign   = :center,\n)\n\nax = Axis(\n    fig[1, 1];\n    title             = \"bar-horizontal · julia · makie · anyplot.ai\",\n    titlesize         = 22,\n    titlecolor        = INK,\n    xlabel            = \"Population (Millions)\",\n    xlabelsize        = 14,\n    xlabelcolor       = INK,\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    leftspinevisible  = false,\n    bottomspinecolor  = INK_SOFT,\n    xgridcolor        = RGBAf(INK.r, INK.g, INK.b, 0.15),\n    ygridvisible      = false,\n    yticksvisible     = false,\n    yticks            = (1:n, plot_countries),\n)\n\nbarplot!(ax, 1:n-1, plot_population[1:n-1]; direction = :x, color = BRAND, width = 0.65)\n\n# Outline the #1 country's bar to give the leader a deliberate focal point,\n# without touching the single brand-green fill shared by every other bar.\nbarplot!(ax, [n], [plot_population[end]]; direction = :x, color = BRAND, width = 0.65,\n         strokewidth = 2.5, strokecolor = INK)\n\n# Value labels at the end of each bar; the leader's label is bolder (larger,\n# full-ink) to match the outline emphasis above.\ntext!(ax, plot_population[1:n-1] .+ maximum(plot_population) * 0.02, 1:n-1;\n      text = string.(round.(Int, plot_population[1:n-1])),\n      align = (:left, :center), fontsize = 12, color = INK_SOFT)\n\ntext!(ax, [plot_population[end] + maximum(plot_population) * 0.02], [n];\n      text = [string(round(Int, plot_population[end]))],\n      align = (:left, :center), fontsize = 14, color = INK)\n\nxlims!(ax, 0, maximum(plot_population) * 1.15)\n\n# --- Save --------------------------------------------------------------------\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}