{"spec_id":"polar-line","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' polar-line: Polar Line Plot\n#' Library: ggplot2 3.5.1 | R 4.4.1\n#' Quality: 82/100 | Created: 2026-09-05\n\nlibrary(ggplot2)\nlibrary(dplyr)\nlibrary(ragg)\n\nset.seed(42)\n\n# --- Theme tokens (see prompts/default-style-guide.md \"Theme-adaptive Chrome\") ----\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\"\nGRID_RULE   <- grDevices::adjustcolor(INK, alpha.f = 0.18)\nIMPRINT_PALETTE <- c(\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\",\n                     \"#AE3030\", \"#2ABCCD\", \"#954477\", \"#99B314\")\n\n# --- Data: mean wind speed by compass bearing for three monitoring stations ----\nbearings <- seq(0, 350, by = 10)\nstations <- c(\"Station A\", \"Station B\", \"Station C\")\nprevailing_bearing <- c(0, 120, 240)\nmean_speed <- c(18, 14, 21)\ngust_amplitude <- c(8, 6, 9)\n\nwind <- tibble::tibble(\n  station = rep(stations, each = length(bearings)),\n  bearing = rep(bearings, times = length(stations)),\n  prevailing = rep(prevailing_bearing, each = length(bearings)),\n  base = rep(mean_speed, each = length(bearings)),\n  amplitude = rep(gust_amplitude, each = length(bearings))\n) %>%\n  mutate(\n    wind_speed = pmax(base + amplitude * cos((bearing - prevailing) * pi / 180) +\n      rnorm(n(), 0, 1.2), 2)\n  )\n\n# Duplicate the bearing-0 point at 360 so each station's line closes into a loop\nwind_closed <- wind %>%\n  filter(bearing == 0) %>%\n  mutate(bearing = 360) %>%\n  bind_rows(wind, .) %>%\n  arrange(station, bearing)\n\n# --- Chrome ------------------------------------------------------------------\nanyplot_theme <- 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 = GRID_RULE, linewidth = 0.3),\n    panel.grid.minor  = element_blank(),\n    axis.line         = element_blank(),\n    axis.title        = element_text(color = INK, size = 10),\n    axis.text         = element_text(color = INK_SOFT, size = 8),\n    plot.title        = element_text(color = INK, size = 12),\n    legend.position   = \"bottom\",\n    legend.background = element_blank(),\n    legend.key        = element_rect(fill = PAGE_BG, color = NA),\n    legend.text       = element_text(color = INK_SOFT, size = 8),\n    legend.title      = element_text(color = INK, size = 10)\n  )\n\n# --- Plot ----------------------------------------------------------------------\np <- ggplot(wind_closed, aes(x = bearing, y = wind_speed, color = station)) +\n  geom_path(linewidth = 1.1) +\n  geom_point(data = filter(wind_closed, bearing != 360), size = 1.8) +\n  scale_color_manual(values = IMPRINT_PALETTE[1:3]) +\n  scale_x_continuous(\n    breaks = seq(0, 315, by = 45),\n    labels = c(\"N\", \"NE\", \"E\", \"SE\", \"S\", \"SW\", \"W\", \"NW\"),\n    limits = c(0, 360)\n  ) +\n  scale_y_continuous(limits = c(0, NA), expand = expansion(mult = c(0, 0.08))) +\n  coord_polar(theta = \"x\", start = 0, direction = 1) +\n  labs(\n    title = \"polar-line · r · ggplot2 · anyplot.ai\",\n    x = NULL,\n    y = \"Wind speed (km/h)\",\n    color = \"Station\"\n  ) +\n  anyplot_theme\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"}