- ggsql labels mean selection age 34 via SQL text geom on histogram.
- Histograms use binwidth=1 on NASA data (n=557, 1959-2024).
- Mission mean 44 stacks at y=49 without overlap.
Posit launched ggsql alpha on April 20, 2026. The package applies Grammar of Graphics to SQL SELECT statements. It creates layered histograms of NASA astronaut ages without R or Python (Posit blog, 2026).
Read Posit's ggsql announcement.
DuckDB powers demos on NASA's astronaut dataset (1959-2024, n=557 records; NASA Astronaut Database via Posit, 2026).
ggsql Applies Grammar of Graphics for Layered Histograms
Leland Wilkinson's Grammar of Graphics (Springer, 2005) breaks plots into data, aesthetics (aes), scales, and geoms. ggsql maps these to SQL clauses.
Users add `geom_histogram(binwidth=1)` on age columns. Linear x-axis spans 20-60 years without truncation. Y-axis shows counts from 0-70, baseline at zero.
Text geoms label means: selection age at x=34, y=66; mission age at x=44, y=49. Offsets avoid overlap (Posit blog example, 2026).
This matches ggplot2 execution in DuckDB or PostgreSQL (ggplot2 documentation, tidyverse.org).
CTEs Prepare Astronaut Data for Precise Layers
ggsql uses Common Table Expressions (CTEs). `QUALIFY ROW_NUMBER() OVER (ORDER BY selection_date) = 1` picks each astronaut's first mission (NASA dataset, n=557, 1959-2024).
Bars display selection age (mean 34 years). Mission age peaks at mean 44 years. Annotations position at y=66, y=49, y=20.
NASA's public database provides raw data, cleaned in Posit's demo (Posit, 2026). Linear scales prevent distortion.
ggplot2 geom_histogram reference.
ggsql Beats BI Tools in SQL Workflows
Analysts run 80% of queries in SQL (Gartner Magic Quadrant for Data Science Platforms, 2025). Tableau uses drag-and-drop. Power BI relies on DAX.
ggsql stays in SQL editors. Positron previews plots inline. Exports yield SVG/PNG for dashboards.
- Tool: ggsql · Syntax: Grammar in SQL · SQL Native: Full · Output Example: Ages 34/44 on histogram
- Tool: ggplot2 · Syntax: R Grammar · SQL Native: Post-query · Output Example: Matching layers post-export
- Tool: Tableau · Syntax: Drag-and-drop · SQL Native: Partial · Output Example: Hides SQL prep
- Tool: Power BI · Syntax: DAX/Visuals · SQL Native: Limited · Output Example: Aggregates before visuals
Tufte Principles Drive ggsql's Data-Ink Ratio
Edward Tufte stresses high data-ink ratios (The Visual Display of Quantitative Information, 1986). ggsql skips gradients and 3D. It uses bars and text.
Window functions build sparklines. No Plotly or Matplotlib needed. VS Code renders instantly.
dbt integrates for pipelines. ggsql handles 1 million rows in under 2 seconds on DuckDB (Posit benchmarks, 2026).
ggsql Scales to Finance with Enterprise Dialects
ggsql targets BigQuery, Databricks, Snowflake. Production aims for sub-second renders on million-row sets.
Financial teams plot S&P 500 daily returns (Yahoo Finance, 2020-2026, n=1,510; mean return 0.04%, SD 1.2%). Set binwidth=0.005 for volatility histograms in USD terms.
Portfolio age distributions layer means at 5.2 years (Gartner, 2025). BI shifts to SQL-native graphics.
Stock return histograms reveal tails: 5% exceed 3% daily (Yahoo Finance data). ggsql annotations flag outliers at x=0.03, y=15.
Wilkinson's Grammar of Graphics.
Data teams unify stacks. Posit bridges SQL to ggplot2 visuals (Posit blog, 2026).
Frequently Asked Questions
What is ggsql?
ggsql from Posit implements Grammar of Graphics in SQL. It creates layered plots like binwidth=1 histograms directly in queries for Quarto and Jupyter.
How does ggsql apply Grammar of Graphics?
ggsql maps SQL to aesthetics and geoms per Wilkinson. Text positions at x=34, 44 label means on linear scales, boosting data-ink ratio.
Which tools support ggsql?
ggsql runs in Quarto, Jupyter, Positron, and VS Code. SQL engines like DuckDB render plots inline for BI workflows.
How does ggsql handle astronaut ages?
CTEs with QUALIFY ROW_NUMBER()=1 select missions from NASA data. Histogram shows mean selection age 34; layers add mission age 44 at precise coordinates.



