{"spec_id":"venn-labeled-items","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' venn-labeled-items: Chartgeist-Style Venn Diagram with Labeled Items\n#' Library: ggplot2 3.5.1 | R 4.4.1\n#' Quality: 86/100 | Created: 2026-06-25\n\nlibrary(ggplot2)\nlibrary(dplyr)\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\"\nINK_MUTED   <- if (THEME == \"light\") \"#6B6A63\" else \"#A8A79F\"\n\n# Imprint palette — circles use first 3 positions\nIMPRINT_PALETTE <- c(\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\",\n                     \"#AE3030\", \"#2ABCCD\", \"#954477\", \"#99B314\")\n\n# Circle geometry: symmetric equilateral triangle layout\nr <- 2.5\nd <- 2.5\n\ncx_a <- 0;       cy_a <- d / sqrt(3)\ncx_b <- -d / 2;  cy_b <- -d / (2 * sqrt(3))\ncx_c <-  d / 2;  cy_c <- -d / (2 * sqrt(3))\n\n# Circle coordinates — inlined\ntheta  <- seq(0, 2 * pi, length.out = 361)\ncirc_a <- data.frame(x = cx_a + r * cos(theta), y = cy_a + r * sin(theta))\ncirc_b <- data.frame(x = cx_b + r * cos(theta), y = cy_b + r * sin(theta))\ncirc_c <- data.frame(x = cx_c + r * cos(theta), y = cy_c + r * sin(theta))\n\n# Tech trends 2025 items per zone\nitems <- data.frame(\n  label = c(\n    \"Metaverse\", \"Web3\", \"AI Pin\", \"Crypto Wallet\",\n    \"Markdown\", \"Obsidian\", \"1Password\",\n    \"YouTube\", \"Chrome\", \"WhatsApp\",\n    \"GPT-4\", \"Copilot\",\n    \"TikTok\", \"Threads\",\n    \"Google Maps\", \"Notion\", \"Spotify\",\n    \"ChatGPT\", \"iPhone\"\n  ),\n  zone = c(\n    rep(\"A\", 4), rep(\"B\", 3), rep(\"C\", 3),\n    rep(\"AB\", 2), rep(\"AC\", 2), rep(\"BC\", 3), rep(\"ABC\", 2)\n  ),\n  stringsAsFactors = FALSE\n)\n\n# Zone anchor centers (hand-tuned for r=2.5, d=2.5 equilateral layout)\nzone_anchors <- data.frame(\n  zone = c(\"A\",   \"B\",    \"C\",    \"AB\",   \"AC\",   \"BC\",   \"ABC\"),\n  ax   = c(0.00, -2.30,   2.30,  -1.20,   1.20,   0.00,   0.00),\n  ay   = c(2.90, -1.70,  -1.70,   0.85,   0.85,  -1.55,   0.15),\n  stringsAsFactors = FALSE\n)\n\n# Spread items vertically within each zone\nitems <- items %>%\n  left_join(zone_anchors, by = \"zone\") %>%\n  group_by(zone) %>%\n  mutate(\n    idx    = row_number(),\n    n_zone = n(),\n    y_off  = (idx - (n_zone + 1) / 2) * 0.52,\n    lx     = ax,\n    ly     = ay + y_off\n  ) %>%\n  ungroup()\n\n# Title (64 chars <= 67 baseline — use full 12pt)\nplot_title <- \"Tech Trends 2025 · venn-labeled-items · r · ggplot2 · anyplot.ai\"\n\n# Assemble plot\np <- ggplot() +\n  # Semi-transparent circle fills (drawn back-to-front so overlaps blend)\n  geom_polygon(data = circ_a, aes(x, y), fill = IMPRINT_PALETTE[1], alpha = 0.13, color = NA) +\n  geom_polygon(data = circ_b, aes(x, y), fill = IMPRINT_PALETTE[2], alpha = 0.13, color = NA) +\n  geom_polygon(data = circ_c, aes(x, y), fill = IMPRINT_PALETTE[3], alpha = 0.13, color = NA) +\n  # Circle outlines\n  geom_path(data = circ_a, aes(x, y), color = IMPRINT_PALETTE[1], linewidth = 1.1) +\n  geom_path(data = circ_b, aes(x, y), color = IMPRINT_PALETTE[2], linewidth = 1.1) +\n  geom_path(data = circ_c, aes(x, y), color = IMPRINT_PALETTE[3], linewidth = 1.1) +\n  # Item labels inside zones\n  geom_text(\n    data     = items,\n    aes(x = lx, y = ly, label = label),\n    color    = INK,\n    size     = 3.2,\n    fontface = \"plain\"\n  ) +\n  # Category names positioned outside each circle\n  annotate(\"text\", x = 0,           y = cy_a + r + 0.65,\n           label = \"Buzzworthy\",       color = IMPRINT_PALETTE[1],\n           size = 4.0, fontface = \"bold\", hjust = 0.5, family = \"serif\") +\n  annotate(\"text\", x = cx_b - 0.4,  y = cy_b - r - 0.60,\n           label = \"Actually Useful\",  color = IMPRINT_PALETTE[2],\n           size = 4.0, fontface = \"bold\", hjust = 1.0, family = \"serif\") +\n  annotate(\"text\", x = cx_c + 0.4,  y = cy_c - r - 0.60,\n           label = \"Everyone Uses It\", color = IMPRINT_PALETTE[3],\n           size = 4.0, fontface = \"bold\", hjust = 0.0, family = \"serif\") +\n  coord_fixed(\n    xlim = c(-5.5, 5.5),\n    ylim = c(-6.5, 5.5)\n  ) +\n  labs(title = plot_title) +\n  theme_void() +\n  theme(\n    plot.background  = element_rect(fill = PAGE_BG, color = PAGE_BG),\n    panel.background = element_rect(fill = PAGE_BG, color = NA),\n    plot.title       = element_text(\n      color  = INK_MUTED,\n      size   = 12,\n      hjust  = 0.5,\n      margin = margin(t = 8, b = 4)\n    ),\n    plot.margin = margin(15, 15, 15, 15)\n  )\n\n# Save — square canvas: 6 x 6 in * 400 dpi = 2400 x 2400 px\nggsave(\n  filename = sprintf(\"plot-%s.png\", THEME),\n  plot     = p,\n  device   = ragg::agg_png,\n  width    = 6,\n  height   = 6,\n  units    = \"in\",\n  dpi      = 400\n)\n"}