{"spec_id":"parallel-basic","library":"ggplot2","language":"r","code":"#' anyplot.ai\n#' parallel-basic: Basic Parallel Coordinates Plot\n#' Library: ggplot2 3.5.1 | R 4.4.1\n#' Quality: 90/100 | Created: 2026-07-24\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_PALETTE <- c(\n  \"#009E73\", # 1 - brand green\n  \"#C475FD\", # 2 - lavender\n  \"#4467A3\"  # 3 - blue\n)\n\n# --- Data -----------------------------------------------------------------\n# Product feature comparison across 6 metrics for 3 market segments.\nn_per_segment  <- 30\nsegment_levels <- c(\"Budget\", \"Mid-range\", \"Premium\")\nseg_idx        <- rep(1:3, each = n_per_segment)\nn              <- length(seg_idx)\n\nprice                  <- pmax(rnorm(n, c(45, 150, 380)[seg_idx], c(15, 40, 90)[seg_idx]), 10)\nrating                 <- pmin(pmax(rnorm(n, c(3.3, 4.0, 4.6)[seg_idx], c(0.4, 0.3, 0.25)[seg_idx]), 1), 5)\nsales_volume           <- pmax(rnorm(n, c(9000, 4000, 900)[seg_idx], c(2500, 1500, 400)[seg_idx]), 100)\ninventory_turnover     <- pmax(rnorm(n, c(14, 8, 3.5)[seg_idx], c(3, 2, 1.2)[seg_idx]), 1)\ncustomer_satisfaction  <- pmin(pmax(rnorm(n, c(72, 84, 93)[seg_idx], c(7, 6, 4)[seg_idx]), 40), 100)\nmarket_share           <- pmax(rnorm(n, c(15, 8, 3)[seg_idx], c(4, 3, 1.5)[seg_idx]), 0.2)\n\ndimension_cols <- c(\"Price\", \"Rating\", \"Sales Volume\", \"Inventory Turnover\",\n                     \"Customer Satisfaction\", \"Market Share\")\n\nproducts <- tibble::tibble(\n  id                       = seq_len(n),\n  category                 = factor(segment_levels[seg_idx], levels = segment_levels),\n  Price                    = price,\n  Rating                   = rating,\n  `Sales Volume`           = sales_volume,\n  `Inventory Turnover`     = inventory_turnover,\n  `Customer Satisfaction`  = customer_satisfaction,\n  `Market Share`           = market_share\n)\n\n# Min-max normalize each dimension to [0, 1] so all axes are comparable.\nproducts_norm <- products %>%\n  mutate(across(all_of(dimension_cols), ~ (. - min(.)) / (max(.) - min(.)), .names = \"{.col}_norm\"))\n\nproducts_long <- products_norm %>%\n  select(id, category, ends_with(\"_norm\")) %>%\n  pivot_longer(cols = ends_with(\"_norm\"), names_to = \"dimension\", values_to = \"value\") %>%\n  mutate(\n    dimension = sub(\"_norm$\", \"\", dimension),\n    dimension = factor(dimension, levels = dimension_cols)\n  )\n\n# Original-scale min/max labels shown at each axis endpoint.\naxis_fmt <- c(\n  \"Price\"                 = \"$%.0f\",\n  \"Rating\"                = \"%.1f★\",\n  \"Sales Volume\"          = \"%.0f\",\n  \"Inventory Turnover\"    = \"%.1f×\",\n  \"Customer Satisfaction\" = \"%.0f%%\",\n  \"Market Share\"          = \"%.1f%%\"\n)\naxis_range <- products %>%\n  summarise(across(all_of(dimension_cols), list(min = min, max = max))) %>%\n  pivot_longer(everything(), names_to = c(\"dimension\", \".value\"), names_pattern = \"(.*)_(min|max)\") %>%\n  mutate(\n    dimension = factor(dimension, levels = dimension_cols),\n    x         = as.numeric(dimension),\n    min_label = sprintf(axis_fmt[as.character(dimension)], min),\n    max_label = sprintf(axis_fmt[as.character(dimension)], max)\n  )\n\n# --- Plot -------------------------------------------------------------------\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         = element_blank(),\n    panel.border       = element_blank(),\n    axis.line          = element_blank(),\n    axis.ticks         = element_blank(),\n    axis.text.y        = element_blank(),\n    axis.title         = element_blank(),\n    axis.text.x        = element_text(color = INK_SOFT, size = 8),\n    plot.title         = element_text(color = INK, size = 12),\n    legend.background  = element_rect(fill = ELEVATED_BG, color = INK_SOFT),\n    legend.text        = element_text(color = INK_SOFT, size = 8),\n    legend.title       = element_text(color = INK, size = 10)\n  )\n\np <- ggplot() +\n  geom_vline(\n    data = axis_range, aes(xintercept = x),\n    color = INK_SOFT, alpha = 0.3, linewidth = 0.4\n  ) +\n  geom_line(\n    data = products_long,\n    aes(x = dimension, y = value, group = id, color = category),\n    alpha = 0.45, linewidth = 0.5\n  ) +\n  geom_point(\n    data = products_long,\n    aes(x = dimension, y = value, color = category),\n    size = 1.5, alpha = 0.6\n  ) +\n  geom_text(\n    data = axis_range, aes(x = x, y = -0.1, label = min_label),\n    color = INK_SOFT, size = 2.6, vjust = 1\n  ) +\n  geom_text(\n    data = axis_range, aes(x = x, y = 1.1, label = max_label),\n    color = INK_SOFT, size = 2.6, vjust = 0\n  ) +\n  scale_color_manual(values = IMPRINT_PALETTE, name = \"Segment\") +\n  scale_x_discrete(labels = function(x) gsub(\" \", \"\\n\", x), expand = expansion(add = 0.6)) +\n  coord_cartesian(ylim = c(-0.22, 1.22), clip = \"off\") +\n  labs(title = \"parallel-basic · r · ggplot2 · anyplot.ai\") +\n  anyplot_theme +\n  theme(plot.margin = margin(t = 20, r = 20, b = 15, l = 20))\n\n# --- Save -------------------------------------------------------------------\nggsave(\n  filename = sprintf(\"plot-%s.png\", THEME),\n  plot     = p,\n  device   = ragg::agg_png,\n  width    = 8,\n  height   = 4.5,\n  units    = \"in\",\n  dpi      = 400\n)\n"}