16

I wanted an internal tool where an analyst pastes any CSV and gets a defensible chart without choosing a type. My first attempt just always drew a bar chart, which is nonsense for two numeric columns.

What worked was giving the model an explicit decision tree keyed on column cardinality and type, and making it justify the choice in one sentence. It now correctly reaches for a scatter when there are two continuous variables and a grouped bar when there's a low-cardinality category.

Still unsure how to handle the 4+ numeric column case gracefully. Small multiples? A parallel coordinates plot feels like too much for non-technical users.

THE PROMPT
Act as a chart-recommendation engine. Input: a CSV. Output: (1) a one-line rationale, (2) a Vega-Lite v5 spec, nothing else.

Follow this decision tree strictly:
- 1 date column + 1+ numeric -> line (multi-series if a low-cardinality category exists, max 6 series, else aggregate).
- 1 categorical (<= 12 distinct) + 1 numeric -> sorted horizontal bar, descending by value.
- 2 numeric, no date -> scatter; if a third categorical exists with <= 6 levels, encode as color.
- 1 numeric only -> histogram with Freedman-Diaconis bin width.
- categorical + categorical -> heatmap of counts.

Rules: never use a pie chart. Never truncate a bar-chart axis (must include 0). Round the rationale to one sentence. Use a colorblind-safe scheme (tableau10). If the CSV has > 5000 rows, add an aggregate transform rather than plotting every point. If no column combination fits the tree, return {"error": "no clear encoding", "columns": [...]} instead of guessing.

1 Answer

9

For the 4+ numeric case I landed on small multiples of scatterplots (a SPLOM) but capped at a 4x4 grid, and if there are more columns I have the model rank them by correlation spread and only show the top 4 most-informative pairs. Parallel coordinates tested badly with our analysts, they read it as spaghetti.

THE PROMPT
When >= 4 numeric columns: compute pairwise Pearson r, select the 4 columns with the highest summed |r| to their neighbors, and emit a SPLOM (scatterplot matrix) with shared scales per row/column and a 1px diagonal histogram.

Your Answer