If you have created graphics in R, my code has probably been involved
I’m creating something new and exciting
+ SQL =
Why am I speaking to you?
Why ggsql?
Why ggsql?
SQL is hugely influential and still heavily used
Many SQL-first or SQL-only data scientists and analysts
They are massively under-served in tooling and visualization
GoG and SQL just fits so good together that it would be criminal not to
A bit about SQL
One of the oldest programming language still in use
Based on Relational Algebra (same theoretical backbone as dplyr)
ANSI SQL (the standard) has been joined by many dialects
DECLARATIVE
TABULAR
A bit about grammar of graphics
A theoretical deconstruction of standard plots into core parts
A theory with many implementations (ggplot2, Vega, D3)
DECLARATIVE
TABULAR
A bit about grammar of graphics
A bit about grammar of graphics
Raw data you want to plot
In tabular form, one record per row (tidy format)
A bit about grammar of graphics
How columns relate to visual aesthetics
How columns relate to statistical properties
A bit about grammar of graphics
Transformation of observation into derived statistics
E.g. binning for a histogram
A bit about grammar of graphics
Mapping of measured values to the aesthetic domain
Definition of mapping function
A bit about grammar of graphics
How to visually represent data
point
rectangle
area
A bit about grammar of graphics
Which subset(s) of data to show
and how…
A bit about grammar of graphics
How the positional aesthetics relate spatially
cartesian
polar
ternary
A bit about grammar of graphics
Non-data-driven styling
Title font
Panel background color
Grid line width
SQL and GoG
Declarative
Modular
Composable
Speakable
SQL and GoG
These qualities makes for exceptional software
They are good for humans
They are good for LLMs
Demo time
Data
SELECT*FROM ggsql:penguinsLIMIT14
species
island
bill_len
bill_dep
flipper_len
body_mass
sex
year
Adelie
Torgersen
39.1
18.7
181
3750
male
2007
Adelie
Torgersen
39.5
17.4
186
3800
female
2007
Adelie
Torgersen
40.3
18
195
3250
female
2007
Adelie
Torgersen
null
null
null
null
null
2007
Adelie
Torgersen
36.7
19.3
193
3450
female
2007
Adelie
Torgersen
39.3
20.6
190
3650
male
2007
Adelie
Torgersen
38.9
17.8
181
3625
female
2007
Adelie
Torgersen
39.2
19.6
195
4675
male
2007
Adelie
Torgersen
34.1
18.1
193
3475
null
2007
Adelie
Torgersen
42
20.2
190
4250
null
2007
Adelie
Torgersen
37.8
17.1
186
3300
null
2007
Adelie
Torgersen
37.8
17.3
180
3700
null
2007
Adelie
Torgersen
41.1
17.6
182
3200
female
2007
Adelie
Torgersen
38.6
21.2
191
3800
male
2007
Mappings
SELECT*FROM ggsql:penguinsVISUALIZE bill_len ASx, bill_dep ASy, species ASfillDRAWpoint/*penguins |> ggplot( aes( x = bill_len, y = bill_dep, color = species ) ) + geom_point()*/
Statistics
SELECT*FROM ggsql:penguinsVISUALIZE species ASx, body_mass ASy, species ASfillDRAWboxplot/*penguins |> ggplot( aes( x = species, y = body_mass, fill = species ) ) + geom_boxplot()*/
Statistics
SELECT*FROM ggsql:penguinsVISUALIZE bill_dep ASx, bill_len ASyDRAWpointMAPPING species AS fillDRAWpointSETTING aggregate =>'mean',fill=>'red',size=>15PARTITION BY species
Statistics
SELECT*FROM ggsql:penguinsVISUALIZE bill_dep ASx, bill_len ASyDRAWpointMAPPING species AS fillDRAWrangeMAPPING bill_len AS ymin, bill_len AS ymaxSETTING aggregate => ('x:mean', 'ymin:min', 'ymax:max')PARTITION BY species
Scales
SELECT*FROM ggsql:penguinsVISUALIZE bill_dep ASx, bill_len ASy, body_mass ASsizeDRAWpointSCALEsizeFROM (0, null) TO (0, 10)/*penguins |> ggplot( aes( x = bill_dep, y = bill_len, size = body_mass ) ) + geom_point() + scale_size( limits = c(0, NA), range = c(0, 10) )*/
Geometries
SELECT*FROM ggsql:penguinsVISUALIZE species ASx, body_mass ASy, species ASfillDRAWboxplotSETTING side =>'left'DRAWviolinSETTING side =>'right'DRAWpointMAPPING null AS fillSETTING position =>'jitter', distribution =>'density', side =>'right',size=>1
Facets
SELECT*FROM ggsql:penguinsVISUALIZE bill_len ASx, bill_dep ASy, species ASfillDRAWpointFACET island