The grammar of graphics
ggsql is a tool for visualising data, combining our 20 years of experience developing ggplot2 with a SQL-native syntax. Unlike most visualisation systems, ggsql has an underlying grammar, based on the Grammar of Graphics by Leland Wilkinson. This is a different approach than the one taken by most tools, which give you a set of pre-defined graphics, like scatterplots, bar charts, and pie charts. ggsql instead gives you a number of independent components that you can combine to solve a very wide set of problems.
This means there’s a learning curve to ggsql: you have to learn a few big ideas about the grammar before you can be productive. But we believe the payoff is worth it. The grammar gives you new vocabulary and new ways to think about visualizations. This allows you to create not only familiar graphics but also newer, better graphics. You’ll gain the ability to look at a visualization that someone else has made, analyse the key components, then recreate it yourself. The hardest part of learning ggsql is likely to be unlearning the preconceptions that you bring over from previous visualization tools.
We’ve tried to make the learning curve as easy as possible by keeping the grammar close to the SQL syntax that you’re already familiar with. You’ll start with a classic SELECT statement to get the data that you want. Then you’ll use VISUALIZE (or VISUALISE 🇬🇧) to switch from creating a table of data to creating a plot of that data. Then you’ll DRAW a layer that maps columns in your data to aesthetics (visual properties), like position, colour, and shape. Then you tweak the SCALEs, the mappings between the data and the visual properties, to make the plot easier to read. Then you FACET the plot to show how the relationships differ across subsets of the data. Finally you finish up by adding LABELs to explain your plot to others. This allows you to produce graphics using the same structured thinking that you already use to design a SQL query.