{"spec_id":"histogram-basic","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' histogram-basic: Basic Histogram\n#' Library: ggplot2 4.0.3 | R 4.6.1\n#' Quality: 82/100 | Updated: 2026-11-26\n\nlibrary(ggplot2)\nlibrary(scales)\nlibrary(ragg)\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\"\n\n# Imprint palette: all eight positions in canonical order\nIMPRINT_PALETTE <- c(\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\",\n                     \"#AE3030\", \"#2ABCCD\", \"#954477\", \"#99B314\")\n\n# Columns: set these to your table's column names\nSALARY <- \"Annual Salary\"  # role: value\n\n# Data: replace this block with your own table, for example df <- read.csv(\"salaries.csv\", check.names = FALSE)\nset.seed(42)\nn <- 400\nsalaries <- c(\n  rnorm(round(n * 0.70), mean = 65000,  sd = 15000),\n  rnorm(round(n * 0.20), mean = 105000, sd = 20000),\n  rnorm(round(n * 0.10), mean = 175000, sd = 30000)\n)\ndf <- tibble::tibble(!!SALARY := pmax(salaries, 28000))\n\n# Plot: reads only df and the constants above\np <- ggplot(df, aes(x = .data[[SALARY]])) +\n  geom_histogram(\n    binwidth  = 5000,\n    boundary  = 0,\n    fill      = IMPRINT_PALETTE[1],\n    color     = alpha(INK, 0.55),\n    linewidth = 0.25\n  ) +\n  scale_x_continuous(\n    labels = label_dollar(scale = 1e-3, suffix = \"k\"),\n    expand = expansion(mult = c(0.01, 0.02))\n  ) +\n  scale_y_continuous(expand = expansion(mult = c(0, 0.08))) +\n  labs(\n    title = \"histogram-basic · r · ggplot2 · anyplot.ai\",\n    x     = SALARY,\n    y     = \"Number of Employees\"\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_blank(),\n    panel.grid.major.y = element_line(color = alpha(INK_SOFT, 0.35), linewidth = 0.2),\n    panel.grid.minor   = element_blank(),\n    axis.title         = element_text(color = INK,      size = 10),\n    axis.text          = element_text(color = INK_SOFT, size = 8),\n    axis.line          = element_line(color = INK_SOFT, linewidth = 0.4),\n    axis.ticks         = element_blank(),\n    plot.title         = element_text(color = INK, size = 12, face = \"bold\",\n                                      margin = margin(b = 10)),\n    plot.margin        = margin(20, 25, 15, 15)\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"}