{"spec_id":"bar-horizontal","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' bar-horizontal: Horizontal Bar Chart\n#' Library: ggplot2 3.5.1 | R 4.4.1\n#' Quality: 88/100 | Created: 2026-08-05\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\"\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\")\nBRAND <- IMPRINT_PALETTE[1]  # ALWAYS first series\n\n# --- Data ---------------------------------------------------------------\n# Survey: \"What best describes your current work arrangement?\"\ndf <- tibble::tibble(\n  arrangement = c(\n    \"Fully remote\",\n    \"Hybrid, 2-3 days in office\",\n    \"Fully in-office\",\n    \"Hybrid, 4 days in office\",\n    \"Flexible, self-directed schedule\",\n    \"Compressed four-day workweek\",\n    \"Job-share arrangement\"\n  ),\n  share_pct = c(34.5, 24.8, 18.3, 12.1, 6.4, 2.7, 1.2)\n)\ndf$is_top <- df$share_pct == max(df$share_pct)\nlabel_gap <- max(df$share_pct) * 0.07\n\n# --- Plot ---------------------------------------------------------------\nplot_title <- \"Preferred Work Arrangement Survey · bar-horizontal · r · ggplot2 · anyplot.ai\"\ntitle_n <- nchar(plot_title)\ntitle_ratio <- if (title_n > 67) 67 / title_n else 1.0\ntitle_fontsize <- max(8, round(12 * title_ratio))\n\np <- ggplot(df, aes(x = reorder(arrangement, share_pct), y = share_pct)) +\n  geom_col(aes(linewidth = is_top), fill = BRAND, color = PAGE_BG, width = 0.7) +\n  scale_linewidth_manual(values = c(`TRUE` = 1.1, `FALSE` = 0.4), guide = \"none\") +\n  geom_text(\n    aes(y = share_pct + label_gap, label = paste0(share_pct, \"%\"), fontface = ifelse(is_top, \"bold\", \"plain\")),\n    hjust = 0, size = 3.2, color = INK\n  ) +\n  scale_y_continuous(expand = expansion(mult = c(0, 0.16))) +\n  coord_flip(clip = \"off\") +\n  labs(\n    title = plot_title,\n    x = NULL,\n    y = \"Share of Respondents (%)\"\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.y = element_blank(),\n    panel.grid.major.x = element_line(color = INK, linewidth = 0.2),\n    panel.grid.minor   = element_blank(),\n    axis.ticks         = element_blank(),\n    axis.title.x       = element_text(color = INK, size = 10, margin = margin(t = 10)),\n    axis.text.x        = element_text(color = INK_SOFT, size = 8),\n    axis.text.y        = element_text(color = INK, size = 9),\n    plot.title         = element_text(color = INK, size = title_fontsize, margin = margin(b = 14)),\n    plot.margin        = margin(t = 16, r = 40, b = 12, l = 12)\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"}