Skip to content

Latest commit

 

History

History
253 lines (210 loc) · 10.9 KB

File metadata and controls

253 lines (210 loc) · 10.9 KB
name RGraphMaker
description Generate publication-ready graphs and data visualizations using R — no R knowledge required. Use this skill whenever the user asks to create, plot, chart, graph, or visualize data using R, or when they upload a dataset (CSV, TSV, Excel) and want any kind of visual output. Triggers on phrases like: "make a bar chart", "plot this data", "create a volcano plot", "visualize my results", "R graph", "ggplot", "heatmap of my data", "scatter plot", "box plot comparison", "interactive chart", "survival curve", "Manhattan plot", "Sankey diagram", "forest plot", "word cloud", "treemap", "network graph", "QQ plot", "ridgeline plot", "Venn diagram", "radar chart", "waterfall chart", or any request for a statistical/scientific figure. Also triggers when the user has data and says things like "show me the distribution", "compare these groups", "what does this data look like", or "publication figure". Supports 50 graph types via ggplot2, base R, and plotly. Outputs PNG, PDF, and/or interactive HTML.

R Graph Maker — Full-Scale No-Code R Visualization Skill

This skill lets anyone create professional R visualizations by describing what they want in plain language. The user never writes R code — you generate, execute, and deliver the output.

Workflow

  1. Understand the request — What graph type? What data? What customizations?
  2. Load or inspect the data — Read the user's CSV/TSV/Excel, or use inline data
  3. Auto-suggest (if no graph type specified) — Run scripts/data_profiler.R on the data
  4. Look up the graph pattern — Find the right reference file from the routing table below
  5. Select the engine — ggplot2 (default), base R, or plotly
  6. Generate the R script — Adapt the template to the user's data and preferences
  7. Apply customizations — Colors, themes, labels per references/customization_guide.md
  8. Execute — Run via Rscript, save outputs to /mnt/user-data/outputs/
  9. Present — Share the file(s) with the user

Auto-Suggest Mode

When the user uploads a dataset without specifying a graph type (e.g., "what graphs can I make from this data?" or "analyze my data and suggest visualizations"), run:

Rscript scripts/data_profiler.R /path/to/data.csv

The profiler outputs JSON with:

  • Data profile: rows, columns, types (numeric/categorical/date), missing data %
  • Domain detection: auto-detects DESeq2, GWAS, survival, flow, network, word frequency data
  • Ranked recommendations: each with graph type, priority (HIGH/MEDIUM/LOW), reason, suggested column mappings (x, y, group), engine, and category

How to present recommendations to the user:

  1. Summarize the data profile (rows, columns, types detected)
  2. Mention any domain detected (e.g., "This looks like differential expression data")
  3. Present the HIGH-priority recommendations first as the top picks
  4. List MEDIUM recommendations as additional options
  5. Mention LOW-priority ones briefly as "also possible"
  6. Ask which graph(s) the user wants to create
  7. When the user picks one, use the suggested columns from the profiler output

Domain detection triggers:

  • DESeq2: columns matching log2FC + padj/pvalue + gene → Volcano, MA Plot
  • GWAS: CHR + BP/position + pvalue → Manhattan Plot
  • Survival: time + status columns → Kaplan-Meier
  • Flow: source + target columns → Sankey / Alluvial
  • Network: node/edge columns → Network Graph
  • Word frequency: word + freq/count columns → Word Cloud

Graph Routing Table

Use this table to find the right reference file. Read the relevant file before generating code.

Category A — Basic / Core (references/graphs_basic.md)

# Graph Type Variants
1 Bar chart vertical, horizontal, grouped, stacked, percentage
2 Line chart single, multi-line, time series
3 Scatter plot basic, regression, colored, bubble, labeled
4 Histogram basic, overlaid, faceted
5 Density plot basic, overlaid, ridgeline
6 Area chart basic, stacked, proportional
7 Pie / Donut chart pie, donut, labeled

Category B — Distribution & Comparison (references/graphs_distribution.md)

# Graph Type Variants
8 Boxplot basic, grouped, jitter, notched
9 Violin plot basic, with boxplot, split
10 Ridgeline / Joy plot basic, quantile-colored
11 Dot plot (Cleveland) basic, grouped
12 Strip / Jitter plot basic, grouped, beeswarm
13 QQ plot basic, grouped
14 Error bar plot bar+error, pointrange
15 Forest plot meta-analysis style
16 Lollipop chart basic, horizontal, colored
17 Dumbbell chart basic, colored

Category C — Relationship & Matrix (references/graphs_relationship.md)

# Graph Type Variants
18 Heatmap tile, clustered, annotated
19 Correlation matrix corrplot, GGally, interactive
20 Pairs / Scatter matrix GGally ggpairs
21 PCA biplot manual ggplot, factoextra

Category D — Scientific / Genomics (references/graphs_scientific.md)

# Graph Type Variants
22 Volcano plot ggplot2, plotly interactive
23 MA plot log-ratio vs mean
24 Manhattan plot GWAS-style
25 Venn diagram 2-5 sets
26 UpSet plot alternative to Venn for many sets
27 Survival curve Kaplan-Meier with risk table

Category E — Specialized (references/graphs_specialized.md)

# Graph Type Variants
28 Waterfall chart financial, sorted
29 Slope chart paired comparison
30 Treemap basic, grouped
31 Waffle chart grid-based proportions
32 Sankey / Alluvial flow diagram
33 Radar / Spider chart multi-axis comparison
34 Network graph igraph, interactive
35 Word cloud basic, shaped
36 ACF / PACF autocorrelation time series

Category F — Gallery Extras (references/graphs_gallery_extras.md)

# Graph Type Variants
37 Connected scatter plot basic, with labels, with arrows
38 2D density plot contour, filled, hexbin, bin2d
39 Parallel coordinates GGally, plotly interactive
40 Circular barplot basic, with labels
41 Dendrogram base R, ggdendro, interactive
42 Circular packing packcircles, bubble fallback
43 Chord diagram circlize, Sankey fallback
44 Streamgraph ggplot2, ggstream
45 Animated chart gganimate GIF, faceted fallback
46 Choropleth map sf, maps, plotly interactive
47 Bubble map ggplot2 + maps
48 3D scatter / surface plotly interactive
49 Diverging stacked bar Likert-style survey
50 Table visualization gt, kableExtra

Engine Selection Logic

Situation Engine Why
Default / publication figure ggplot2 Best aesthetics, most flexible
User says "base R" or wants classic style base R Simpler, traditional look
User wants interactive / hover / zoom plotly HTML widget with interactivity
User says "interactive" or "hover" plotly Automatic interactive trigger
Complex static + wants HTML too ggplot2 → ggplotly() Best of both worlds

Output Format Logic

Default to PNG + PDF when unspecified. If user says "interactive", produce HTML. Always save to /mnt/user-data/outputs/.

ggsave("plot.png", plot = p, width = 10, height = 7, dpi = 300)  # PNG
ggsave("plot.pdf", plot = p, width = 10, height = 7)              # PDF
htmlwidgets::saveWidget(ggplotly(p), "plot.html", selfcontained = TRUE)  # HTML

Data Handling

Reading user data

library(readr); library(readxl)
if (grepl("\\.csv$", filepath))    df <- read_csv(filepath)
if (grepl("\\.tsv$", filepath))    df <- read_tsv(filepath)
if (grepl("\\.xlsx?$", filepath))  df <- read_excel(filepath)

Column name handling

  • Print colnames(df) and str(df) first to understand the data
  • Use actual column names — never guess
  • Spaces in names: use backticks `Column Name`
  • Ask the user which columns to use if ambiguous

Script Generation Rules

  1. Always start with library loading — only what's needed
  2. Always set set.seed(42) if any randomness is involved
  3. Always wrap main plot in tryCatch() for graceful error handling
  4. Always print a success message with the output file path
  5. Package management: Check before loading. If a package is not installed, install it:
    if (!requireNamespace("pkgname", quietly = TRUE))
      install.packages("pkgname", repos = "https://cloud.r-project.org", quiet = TRUE)
  6. Source scripts/theme_presets.R for consistent theming when relevant
  7. Read the relevant graph reference file before generating code

Pre-Installed vs Install-on-Demand Packages

Always available (pre-installed): ggplot2, plotly, ggrepel, ggridges, corrplot, heatmaply, GGally, factoextra, cowplot, patchwork, igraph, ggalluvial, ggbeeswarm, ggpubr, ggsci, ggthemes, survival, forecast, scales, dplyr, tidyr, readr, readxl

May need installation: survminer, treemapify, wordcloud, wordcloud2, UpSetR, ggVennDiagram, VennDiagram, waffle, fmsb, tidytext

When a graph type needs a package that may not be installed, the reference files include ggplot2-only fallback patterns that work without extra dependencies. Prefer the dedicated package when available, but fall back to pure ggplot2 if installation fails.

Script Template

# ============================================================
# Graph: [TYPE] | Engine: [ggplot2/base/plotly]
# Generated by r-graph-maker skill
# ============================================================

# --- Libraries ---
library(ggplot2)

# --- Read Data ---
df <- read.csv("/path/to/data.csv")

# --- Data Preparation ---
# transformations, filtering, factor reordering

# --- Build Plot ---
p <- ggplot(df, aes(x = col1, y = col2)) +
  geom_point() +
  labs(title = "Title", x = "X", y = "Y") +
  theme_minimal(base_size = 14)

# --- Save Outputs ---
ggsave("/mnt/user-data/outputs/plot.png", plot = p, width = 10, height = 7, dpi = 300)
ggsave("/mnt/user-data/outputs/plot.pdf", plot = p, width = 10, height = 7)
cat("Done! Files saved.\n")

Error Handling

If the R script fails:

  1. Read the error message carefully
  2. Common fixes: wrong column names, factor vs numeric confusion, na.rm = TRUE
  3. Fix and re-run — don't ask the user to debug
  4. If data itself is the problem, explain clearly

Important Notes

  • Always read user's actual data before generating code — never assume column names
  • User uploads are at /mnt/user-data/uploads/
  • Generate R scripts in /home/claude/, execute, present outputs from /mnt/user-data/outputs/
  • For plotly HTML > 5MB, warn the user about file size
  • Prefer ggplot2 unless user specifically requests otherwise
  • When in doubt about graph type, suggest the best option based on data structure