Frequently Asked Questions
Getting Started
ggsql is a SQL extension for declarative data visualization based on Grammar of Graphics principles. It allows you to combine SQL data queries with visualization specifications in a single, composable syntax.
SELECT date, revenue, region FROM sales
VISUALISE date AS x, revenue AS y, region AS color
DRAW lineSee the installation instruction in the Getting started tutorial.
ggsql is built in a modular way so we can gradually add new backends to it. Currently, ggsql works with DuckDB and SQLite, but we are planning on expanding that soon!
We have designed ggsql to be modular, both when it comes to the database input and the final rendering. For the first phase of the development we have chosen to use Vegalite as a renderer as it has allowed us to iterate quickly, but we do not envision Vegalite to remain the only, nor default writer in the future.
Syntax & Usage
VISUALISE and VISUALIZE?
Both spellings are supported - use whichever you prefer. The grammar accepts both British (VISUALISE) and American (VISUALIZE) spellings.
Add multiple DRAW clauses to your query. Each DRAW creates a new layer:
SELECT x, y FROM data
VISUALISE x, y
DRAW line MAPPING x AS x, y AS y
DRAW point MAPPING x AS x, y AS yUse the LABEL clause:
SELECT date, revenue FROM sales
VISUALISE date AS x, revenue AS y
DRAW line
LABEL title => 'Sales Over Time', x => 'Date', y => 'Revenue (USD)'VISUALISE clause
Some parts of the syntax are passed on directly to the database, such as the FILTER and ORDER BY clauses in DRAW.
SELECT date, revenue FROM sales
VISUALISE date AS x, revenue AS y
DRAW line
DRAW point
FILTER revenue = max(revenue)Further, any query before the VISUALISE clause is passed directly to the database so anything supported by your backend can go in there.
ggsql integrates very deeply with the database backends and handles all statistical transformations as SQL queries. This means that if you need to make a histogram of 1 billion observations, you’ll only ever fetch the values of each histogram bin, not the full dataset.
ggsql does not yet support interactive functionality like tool tips and zooming. This is a point of focus for us and we will rather get the syntax and implementation right than rush to it.
Troubleshooting
Add SCALE x VIA date to tell ggsql to treat the x-axis as temporal data:
SELECT date, value FROM data
VISUALISE date AS x, value AS y
DRAW line
SCALE x VIA datePlease open an issue on our GitHub repository.