Member-only story
Visualizing SQL Queries in R: How to Use ggsql
View SQL syntax as a graph with the convenience of ggplot2 elements, Here’s how to do it with the ggsql package.
Most data analysts already know how to write a SELECT statement. SQL is the lingua franca of data work — dependable, composable, and nearly universal across industries. Getting that data into a visualization, though, has always required a separate step: export to R, load ggplot2, map aesthetics, add layers. That gap is small but real, and for analysts who live in SQL, it can feel like crossing a border every time a chart needs to be made.
ggsql closes that gap. Released in alpha by Posit in April 2026, ggsql is an implementation of the grammar of graphics built directly on SQL syntax. You write a query, and the visualization is part of the query. The same composable, declarative thinking that makes SQL powerful for data manipulation extends naturally into data presentation.
For R users who already rely on ggplot2 for visualization and DBI or DuckDB for database work, ggsql adds a new option: a single query syntax that handles both transformation and display, with bidirectional data flow into and out of R sessions.









