{"spec_id":"parliament-basic","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' parliament-basic: Parliament Seat Chart\n#' Library: ggplot2 3.5.1 | R 4.4.1\n#' Quality: 91/100 | Created: 2026-05-17\n\nlibrary(ggplot2)\nlibrary(dplyr)\nlibrary(tidyr)\nlibrary(ragg)\n\nset.seed(42)\n\n# --- Theme tokens -----------------------------------------------------------\nTHEME       <- Sys.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG     <- if (THEME == \"light\") \"#FAF8F1\" else \"#1A1A17\"\nELEVATED_BG <- if (THEME == \"light\") \"#FFFDF6\" else \"#242420\"\nINK         <- if (THEME == \"light\") \"#1A1A17\" else \"#F0EFE8\"\nINK_SOFT    <- if (THEME == \"light\") \"#4A4A44\" else \"#B8B7B0\"\nIMPRINT   <- c(\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\",\n                 \"#AE3030\", \"#2ABCCD\", \"#954477\")\n\n# --- Data -------------------------------------------------------------------\n# Create party data with seat counts\nparties <- data.frame(\n  party = c(\"Progressive Alliance\", \"Democratic Union\", \"Conservative Coalition\",\n            \"Labor Front\", \"Green Bloc\", \"Reform Party\", \"Centrist Movement\"),\n  seats = c(142, 118, 97, 85, 68, 62, 48),\n  stringsAsFactors = FALSE\n)\n\n# Generate seat coordinates in semicircular parliament layout\n# Semicircle arrangement: left to right, bottom to top (multiple arcs)\nseats_per_row <- 18\ntotal_seats <- sum(parties$seats)\nnum_rows <- ceiling(total_seats / seats_per_row)\n\n# Create seat positions\nseat_data <- data.frame()\nseat_idx <- 1\n\nfor (i in 1:nrow(parties)) {\n  party_name <- parties$party[i]\n  party_seats <- parties$seats[i]\n  party_color_idx <- min(i, length(IMPRINT))\n\n  for (j in 1:party_seats) {\n    row_idx <- ceiling(seat_idx / seats_per_row)\n    col_idx <- ((seat_idx - 1) %% seats_per_row) + 1\n\n    # Semicircular geometry: position seats in concentric arcs\n    # Angle spans from 0 to pi (semicircle)\n    angle <- (col_idx - 1) / (seats_per_row - 1) * pi\n    radius <- 1.5 + (row_idx - 1) * 0.8\n\n    x <- radius * cos(angle)\n    y <- radius * sin(angle)\n\n    seat_data <- rbind(seat_data, data.frame(\n      x = x,\n      y = y,\n      party = party_name,\n      color_idx = party_color_idx,\n      seat_id = seat_idx,\n      stringsAsFactors = FALSE\n    ))\n\n    seat_idx <- seat_idx + 1\n  }\n}\n\n# Map color indices to actual colors\nseat_data$color <- IMPRINT[seat_data$color_idx]\n\n# --- Plot -------------------------------------------------------------------\np <- ggplot(seat_data, aes(x = x, y = y, fill = party)) +\n  geom_point(\n    aes(color = party),\n    size = 5,\n    alpha = 0.85,\n    shape = 21,\n    stroke = 0.3,\n    show.legend = TRUE\n  ) +\n  scale_color_manual(\n    values = setNames(IMPRINT[1:nrow(parties)], parties$party),\n    guide = guide_legend(ncol = 1, title = \"Party\", title.position = \"top\")\n  ) +\n  scale_fill_manual(\n    values = setNames(IMPRINT[1:nrow(parties)], parties$party),\n    guide = \"none\"\n  ) +\n  coord_fixed() +\n  labs(\n    title = \"parliament-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.major  = element_blank(),\n    panel.grid.minor  = element_blank(),\n    panel.border      = element_blank(),\n    axis.title        = element_blank(),\n    axis.text         = element_blank(),\n    axis.ticks        = element_blank(),\n    plot.title        = element_text(color = INK, size = 24, hjust = 0.5, margin = margin(b = 20)),\n    plot.margin       = margin(20, 20, 20, 20),\n    legend.background = element_rect(fill = ELEVATED_BG, color = INK_SOFT),\n    legend.text       = element_text(color = INK_SOFT, size = 16),\n    legend.title      = element_text(color = INK, size = 18),\n    legend.position   = \"right\",\n    legend.margin     = margin(10, 10, 10, 10)\n  )\n\n# --- Save -------------------------------------------------------------------\nggsave(\n  filename = sprintf(\"plot-%s.png\", THEME),\n  plot     = p,\n  device   = ragg::agg_png,\n  width    = 16,\n  height   = 9,\n  units    = \"in\",\n  dpi      = 300\n)\n"}