I love ggsql!
/ 2 min read
It’s still early days, but there’s so much to love about ggsql! The team behind it gave good reasons why use ggsql but I’d like to give some more.
It’s great for newcomers!
The playground is instant, great to play with it. WASM magic. Not so with ggplot, the best I found is Esquisse but it’s slow.
Not being tied to a programming language, it’s much easier to start or to be adopted from different programming languages.
The API is much clearer (more below) so it’s less confusing.
The API is much much better!
It’s like they fixed all the quirks! Some random examples:
Color / Fill
I got confused with color / fill, but now with border and fill it’s obvious. And color is basically a shorthand to set both border and fill.
Aesthetics vs Mappings/Settings
Aesthetics are usually called mappings, and we don’t need to use the aes() that I always forget! And settings are explicit. Much clearer.
Better overrides
If I’ve set up the fill as red, but I want to map some variable to fill, the data should override the red setting, right? Not in ggplot:
ggplot(penguins) + geom_bar(aes(x=species, fill=sex), fill="red")VISUALISE bill_len AS x, bill_dep AS y, species AS fill FROM ggsql:penguinsDRAW point MAPPING body_mass AS size SETTING fill => 'red', stroke => nullLess quirky chart setups
I’m all for pushing for better chart representations, but sometimes a pie chart is just yummy. But setting it up in ggplot melts my brain. Empty x? Theta?
ggplot(df, aes(x = "", y = value, fill = group)) + geom_col() + coord_polar(theta = "y")So much more readable:
DRAW bar MAPPING species AS fillPROJECT TO polarConclusion
I’ve heard a lot of people saying something like “what problem does it solve?” but the question is more the other way around:
When ggsql has all the ggplot functionality and plugins, why would you go with ggplot?
It’s language agnostic, easier to read and learn, better with LLMs, faster (at least online), integrates perfectly with SQL and works nicely with the rest.