Advanced Visualizations as an Example
Europa-Universität Flensburg
2026-06-11
Part 1 — AI tools
Live demo: seeing failure in real time
Part 2 — Publication-ready figures
Live demo + exercise
Note
The tools will change every six months. The habits we build today will not.
AI predicts plausible next tokens given its training data.
It does not:
The consequence:
Confidence is not correctness. Fluent-looking code is not correct code.
Hallucination is structural, not a glitch to be patched away.
Tip
A model trained on Stack Overflow posts from 2022 will confidently emit syntax that no longer works in ggplot2 3.4.0.
Note
What about AI with web search? Tools like Perplexity or Claude with research mode retrieve current text — partially lifting the training-cutoff limitation. But retrieved text is still summarised by a model that cannot verify it. The hallucination and reasoning limitations remain.
AI completes boilerplate you already know how to write
Risk: low
Gain: modest
Use when you would have typed it anyway
Ask for options, strategies, chart recommendations — you decide
Risk: medium
Gain: high
Works best when you have strong domain knowledge
Paste your own code; ask what is wrong or what a referee would criticise
Risk: low
Gain: builds critical skill
Extremely useful, low-risk
Important
The choice of mode is itself the skill. The session returns to this after every demo.
Note
Modes combine. A typical workflow: use thought partner to sketch a plan, correct it yourself, then autocomplete fills in the code. Use code reviewer afterwards to catch what you missed.
Package hallucination AI invents plausible-sounding packages or functions that do not exist. A USENIX Security 2025 study across 16 models found ~20% of recommended packages were hallucinations. In R, this is silent until library() throws an error.
Stale API knowledge Deprecated arguments (size= → linewidth= in ggplot2 3.4.0), renamed functions, moved packages. The model was trained on older code. It cannot know what changed.
Vibe coding Accepting AI output without reading it. Re-prompting when it breaks without diagnosing why. Each unread iteration makes the next harder to understand.
prompt → inspect → run → diagnose
↑ │
└──────────────────────────────┘
Inspect — read the code before running it. Does it do what you asked?
Diagnose — when it breaks, understand why before re-prompting.
Note
Students who skip inspect and diagnose are vibe coding, even if they do not call it that.
This habit is what makes AI use durable as tools change. Everything else in this session may be obsolete in two years. This will not be.
Tip
Watch for:
Exploratory — default output
Publication-ready
Exploratory
5 lines. Default output.
Publication-ready
gapminder |>
filter(year == 2007) |>
ggplot(aes(x = gdpPercap,
y = lifeExp,
color = continent)) +
geom_point(alpha = 0.7, size = 2) +
geom_text_repel(
aes(label = country),
data = \(d) filter(d, country == "Germany"),
size = 4, nudge_x = -1.5, nudge_y = -2.0,
min.segment.length = 0,
show.legend = FALSE
) +
geom_text_repel(
aes(label = country),
data = \(d) filter(d, country == "Afghanistan"),
size = 4, nudge_x = -0.75, nudge_y = -3,
min.segment.length = 0,
show.legend = FALSE
) +
geom_text_repel(
aes(label = country),
data = \(d) filter(d, country == "China"),
size = 4, nudge_x = 0.5, nudge_y = -10,
min.segment.length = 0,
show.legend = FALSE
) +
scale_x_log10(
labels = label_dollar(suffix = "k", scale = 0.001)) +
scale_color_viridis_d() +
theme_classic(base_size = 11) +
labs(
x = "GDP per capita (USD, log scale)",
y = "Life expectancy (years)",
color = NULL,
caption = "Source: Gapminder. Year: 2007."
)Three different problems — three different fixes.
| Label | Problem | Example | Fix |
|---|---|---|---|
| Ugly | Aesthetic | Grey background, gdpPercap as axis label |
theme_classic(), labs() |
| Bad | Perceptual | Wrong chart type, overlapping labels, spaghetti | Rethink the encoding |
| Wrong | Mathematical | No uncertainty, truncated axis, wrong aggregation | Fix the underlying logic |
Important
“It doesn’t look great” is not a diagnosis. \(\rightarrow\) “The y-axis is truncated and the comparison is therefore wrong” is.
“What predicts life expectancy, and how uncertain are we?”
Figure 3
Note
Key geom: geom_pointrange() — estimate + uncertainty in one layer
“How does life expectancy distribute across continents?”
Figure 4
Note
Key geoms: geom_violin() + geom_jitter() — shape AND raw data
“Does the income–health relationship vary by continent?”
Figure 5
Note
Key geoms: geom_smooth(method = "lm") + facet_wrap() — relationship × group
“How has life expectancy evolved across European countries?”
Figure 6
Note
Key geoms: geom_line() + gghighlight() — focus without removing context
“Did the policy have an effect, and when did it start?”
Figure 7
Note
Key geoms: geom_pointrange() + geom_vline() — pre/post symmetry + event marker
Warning
AI defaults to whatever was most common in its training data — usually a bar chart.
You must choose the chart type before you prompt.
| Question type | Chart | Key geom(s) |
|---|---|---|
| Regression coefficients | Coefficient plot | geom_pointrange() |
| Distributions across groups | Violin + jitter | geom_violin() + geom_jitter() |
| Bivariate with heterogeneity | Faceted scatter | geom_smooth() + facet_wrap() |
| Time series, multiple units | Highlighted lines | geom_line() + gghighlight() |
| Event study / DiD | Centered point-range | geom_pointrange() + geom_vline() |
theme_classic() (or similar) — no default grey backgroundlabs(caption = ...)ggsave() with explicit dimensions — never the RStudio Export buttonpatchwork — multi-panel layout
ggrepel — non-overlapping labels
gghighlight — focus attention
AI is strong on:
AI struggles with:
patchwork)linewidth vs size)Note
AI can get you to about 70% of a publication-ready figure. The last 30% requires judgment you cannot delegate.
Tip
Watch for:
Available via Github Classroom
Track A — suggested starting points
Track B — bring your own question
Important
Before opening any AI tool: Write one sentence justifying your chart type choice.
Error diagnosis — paste a render error with the surrounding chunk
“What is causing this error?”
Reliable on YAML errors and chunk option problems.
Goal-finding — ask how to achieve a specific Quarto output
“How do I make a figure span the full slide width in Reveal.js?”
AI as documentation shortcut — always verify at quarto.org.
Prose refinement — describe your figure and ask whether the claim holds
“Is this claim supported by the figure? Can it be more concise?”
Most tools accept a screenshot — share one directly. If yours does not, describing the figure forces the clarity the caption needs anyway.
One thing AI is genuinely useful for in your workflow
One thing you would never fully delegate to AI
One habit from today you will keep using after the course
Note
Next session: Recap — send me your question until the end of the week.