{"spec_id":"chessboard-basic","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' chessboard-basic: Chess Board Grid Visualization\n#' Library: ggplot2 3.5.1 | R 4.4.1\n#' Quality: 93/100 | Created: 2026-05-17\n\nlibrary(ggplot2)\nlibrary(dplyr)\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# --- Data -------------------------------------------------------------------\n# Create 8x8 chessboard with algebraic notation\n# Columns: a-h (1-8), Rows: 1-8\n# Light square at h1 and a8 (standard chess convention)\n\nboard <- expand.grid(\n  col = 1:8,\n  row = 1:8\n) %>%\n  mutate(\n    # Alternate colors: (col + row) %% 2 determines light/dark\n    # h1 (col=8, row=1) should be light: (8+1)%%2 = 1 (light)\n    is_light = (col + row) %% 2 == 1,\n    square_color = if_else(is_light, \"#E8D5B7\", \"#8B7355\")\n  )\n\n# --- Plot -------------------------------------------------------------------\np <- ggplot(board, aes(x = col, y = row)) +\n  geom_tile(aes(fill = square_color), color = NA, width = 1, height = 1) +\n  scale_fill_identity() +\n  scale_x_continuous(\n    breaks = 1:8,\n    labels = c(\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"),\n    limits = c(0.5, 8.5),\n    expand = c(0, 0)\n  ) +\n  scale_y_continuous(\n    breaks = 1:8,\n    labels = as.character(1:8),\n    limits = c(0.5, 8.5),\n    expand = c(0, 0)\n  ) +\n  coord_fixed(ratio = 1) +\n  labs(\n    title = \"chessboard-basic · ggplot2 · anyplot.ai\",\n    x = NULL,\n    y = NULL\n  ) +\n  theme_minimal(base_size = 14) +\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        = element_blank(),\n    panel.border      = element_rect(color = INK_SOFT, fill = NA, linewidth = 0.5),\n    axis.title        = element_blank(),\n    axis.text.x       = element_text(color = INK, size = 20),\n    axis.text.y       = element_text(color = INK, size = 20),\n    plot.title        = element_text(color = INK, size = 24, hjust = 0.5),\n    plot.margin       = unit(c(20, 20, 20, 20), \"pt\")\n  )\n\n# --- Save -------------------------------------------------------------------\nggsave(\n  filename = sprintf(\"plot-%s.png\", THEME),\n  plot     = p,\n  device   = ragg::agg_png,\n  width    = 9,\n  height   = 9,\n  units    = \"in\",\n  dpi      = 300\n)\n"}