{"spec_id":"rose-basic","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' rose-basic: Basic Rose Chart\n#' Library: ggplot2 3.5.1 | R 4.4.1\n#' Quality: 93/100 | Created: 2026-07-25\n\nlibrary(ggplot2)\nlibrary(scales)\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]\n\n# --- Data --------------------------------------------------------------------\n# Average monthly rainfall for a temperate maritime city — wet winters,\n# dry summers, the seasonal cycle a coxcomb/rose chart is built to reveal.\nmonths <- factor(month.abb, levels = month.abb)\nseasonal_signal <- 95 + 55 * cos(2 * pi * (seq_along(months) - 1) / 12)\nrainfall_mm <- pmax(15, seasonal_signal + rnorm(12, mean = 0, sd = 8))\n\ndf <- tibble::tibble(month = months, rainfall_mm = rainfall_mm)\n\n# --- Plot ---------------------------------------------------------------------\n# Half a bar-width rotation centers January at 12 o'clock instead of its edge.\nstart_offset <- -(2 * pi / 12) / 2\n\ntitle_text <- \"rose-basic · r · ggplot2 · anyplot.ai\"\ntitle_fontsize <- if (nchar(title_text) > 67) round(12 * 67 / nchar(title_text)) else 12\n\np <- ggplot(df, aes(x = month, y = rainfall_mm, alpha = rainfall_mm)) +\n  geom_col(fill = BRAND, color = PAGE_BG, linewidth = 0.4, width = 1) +\n  coord_polar(theta = \"x\", start = start_offset) +\n  scale_y_continuous(\n    limits = c(0, max(df$rainfall_mm) * 1.15),\n    breaks = pretty(c(0, df$rainfall_mm), n = 4),\n    expand = c(0, 0)\n  ) +\n  scale_alpha_continuous(range = c(0.55, 1), guide = \"none\") +\n  labs(title = title_text, x = NULL, y = \"Rainfall (mm)\") +\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   = element_line(color = scales::alpha(INK, 0.15), linewidth = 0.3),\n    panel.grid.minor   = element_blank(),\n    axis.title.y       = element_text(color = INK_SOFT, size = 8),\n    axis.title.x       = element_blank(),\n    axis.text.x        = element_text(color = INK, size = 10, face = \"bold\"),\n    axis.text.y        = element_text(color = INK_SOFT, size = 8),\n    axis.ticks         = element_blank(),\n    plot.title         = element_text(color = INK, size = title_fontsize, hjust = 0.5, margin = margin(b = 12)),\n    plot.margin        = margin(t = 20, r = 30, b = 10, l = 30)\n  )\n\n# --- Save ---------------------------------------------------------------------\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"}