7.6 AI in Data Visualization
AI tools are beginning to assist with visualization tasks at multiple stages of the process (Wu et al. 2024).
7.6.1 How AI Assists with Visualization
- Chart selection: Describe your data and your question to an AI assistant, and it can recommend appropriate chart types. “I have monthly sales data for three product lines over two years — what’s the best way to show trends?” produces a concrete recommendation with rationale.
- Code generation: AI can generate
ggplot2code from natural language descriptions. “Create a scatter plot of mpg vs. weight from mtcars, colored by number of cylinders, with a trend line” produces working R code that you can run and modify. - Design iteration: Once you have a basic plot, AI can suggest improvements — better color palettes, clearer labels, removal of chart junk — based on the design principles covered in this chapter.
- Automated insights: Emerging tools can analyze a visualization and generate natural language descriptions of the patterns it shows, helping analysts articulate what they see (Hoque and Islam 2025).
Example: AI-Assisted Visualization
Prompt to Claude Code:
Create a scatter plot showing the relationship between horsepower and miles per gallon in mtcars, colored by number of cylinders, with a trend line for each group
AI-generated code:
ggplot(mtcars, aes(x = hp, y = mpg, color = factor(cyl))) +
geom_point(size = 2) +
geom_smooth(method = "lm", se = FALSE) +
theme_minimal() +
labs(title = "MPG vs. Horsepower by Cylinder Count",
x = "Horsepower", y = "Miles per Gallon", color = "Cylinders")What to evaluate: The AI chose geom_smooth(method = "lm") for the trend lines — is a linear fit appropriate here, or would a curved fit (method = "loess") better capture the relationship? It used se = FALSE to hide confidence bands — should those be shown for a presentation to stakeholders? The color palette is ggplot2’s default — would scale_color_viridis_d() be more accessible? The AI produced correct, runnable code, but the design decisions still require human judgment.
7.6.2 Limitations
AI-generated visualizations require the same critical evaluation as AI-generated code. An AI might choose a chart type that technically works but obscures the key insight, select a color scheme that is not colorblind-accessible, or produce a visualization with misleading axis scaling. The design principles and Grammar of Graphics concepts in this chapter give you the vocabulary to evaluate and improve AI-generated visualizations — just as the R skills from Chapter 3 let you evaluate AI-generated code.