Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ A SQL extension for declarative data visualization based on the Grammar of Graph
SELECT date, revenue, region FROM sales WHERE year = 2024
VISUALISE date AS x, revenue AS y, region AS color
DRAW line
LABEL title => 'Sales by Region'
TITLE main => 'Sales by Region'
```

The user-facing site is at <https://ggsql.org>. The README at [`README.md`](README.md) is the public introduction.

## Authoritative docs

**Anything about ggsql syntax or semantics belongs in [`doc/`](doc/), not in any AGENTS.md file.** That includes clause behaviour (`VISUALISE`, `DRAW`, `PLACE`, `SCALE`, `FACET`, `PROJECT`, `LABEL`), layer types, scales, aesthetics, and coordinate systems. AGENTS.md files describe the implementation around those features — they should link to `doc/syntax/` rather than restate.
**Anything about ggsql syntax or semantics belongs in [`doc/`](doc/), not in any AGENTS.md file.** That includes clause behaviour (`VISUALISE`, `DRAW`, `PLACE`, `SCALE`, `FACET`, `PROJECT`, `TITLE`), layer types, scales, aesthetics, and coordinate systems. AGENTS.md files describe the implementation around those features — they should link to `doc/syntax/` rather than restate.

**Writing ggsql queries:** when you need to author or modify a ggsql query, use the vendored skill at [`doc/vendor/SKILL.md`](doc/vendor/SKILL.md). It is the source of truth for the syntax Claude should produce; do not invent clauses, settings, aesthetics, or layer types beyond what it documents.

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ determines whether text boxes get drawn and additional settings `padding`,

### Changed

- **Breaking**: The `SCALE ... RENAMING` sub clause is renamed to
`SCALE ... LABEL`.
- **Breaking**: The `LABEL` clause is renamed to `TITLE`. The keyword `title`
is now `main` and the `subtitle` keyword is now `sub`.
- Registering a DataFrame of more than 2,048 rows with the DuckDB reader
appends it with DuckDB's Arrow appender rather than one `INSERT` per
2,048-row chunk, about twice as fast on large frames (#617).
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ VISUALISE date AS x, revenue AS y, region AS color
DRAW line
SCALE x
SETTING breaks => 'month'
LABEL title => 'Sales by Region'
TITLE main => 'Sales by Region'
```

## Why?
Expand Down
16 changes: 8 additions & 8 deletions doc/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ website:
href: syntax/clause/facet.qmd
- text: "`PROJECT`"
href: syntax/clause/project.qmd
- text: "`LABEL`"
href: syntax/clause/label.qmd
- text: "`TITLE`"
href: syntax/clause/title.qmd
- text: "---"
- text: "`TABULATE`"
href: syntax/clause/tabulate.qmd
- text: "`LABEL`"
href: syntax/clause/label-tabulate.qmd
- text: "`TITLE`"
href: syntax/clause/title-tabulate.qmd
- text: "`SPAN`"
href: syntax/clause/span.qmd
- text: "`FORMAT`"
Expand Down Expand Up @@ -117,14 +117,14 @@ website:
href: syntax/clause/facet.qmd
- text: "`PROJECT`"
href: syntax/clause/project.qmd
- text: "`LABEL`"
href: syntax/clause/label.qmd
- text: "`TITLE`"
href: syntax/clause/title.qmd
- section: "Tabulate clauses"
contents:
- text: "`TABULATE`"
href: syntax/clause/tabulate.qmd
- text: "`LABEL`"
href: syntax/clause/label-tabulate.qmd
- text: "`TITLE`"
href: syntax/clause/title-tabulate.qmd
- text: "`SPAN`"
href: syntax/clause/span.qmd
- text: "`FORMAT`"
Expand Down
6 changes: 3 additions & 3 deletions doc/faq.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ DRAW point
::: {.callout-note collapse="true"}
## How do I set axis labels and a title?

Use the `LABEL` clause:
Use the `TITLE` clause:

```ggsql
SELECT date, revenue FROM sales
VISUALISE date AS x, revenue AS y
DRAW line
LABEL
title => 'Sales Over Time',
TITLE
main => 'Sales Over Time',
x => 'Date',
y => 'Revenue (USD)'
```
Expand Down
12 changes: 6 additions & 6 deletions doc/gallery/examples/bar-chart.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ SELECT species, COUNT(*) as count FROM ggsql:penguins
GROUP BY species
VISUALISE species AS x, count AS y, species AS fill
DRAW bar
LABEL
title => 'Penguin Count by Species',
TITLE
main => 'Penguin Count by Species',
x => 'Species',
y => 'Count'
```
Expand All @@ -41,8 +41,8 @@ GROUP BY species
VISUALISE species AS x, count AS y, species AS fill
DRAW bar
PROJECT y, x TO cartesian
LABEL
title => 'Penguin Count by Species',
TITLE
main => 'Penguin Count by Species',
x => 'Species',
y => 'Count'
```
Expand All @@ -55,8 +55,8 @@ When you don't specify a y aesthetic, ggsql automatically counts occurrences:
SELECT species FROM ggsql:penguins
VISUALISE species AS x
DRAW bar
LABEL
title => 'Penguin Distribution',
TITLE
main => 'Penguin Distribution',
x => 'Species',
y => 'Count'
```
12 changes: 6 additions & 6 deletions doc/gallery/examples/faceted.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ SELECT bill_len, bill_dep, species FROM ggsql:penguins
VISUALISE bill_len AS x, bill_dep AS y
DRAW point
FACET species
LABEL
title => 'Bill Dimensions by Species',
TITLE
main => 'Bill Dimensions by Species',
x => 'Bill Length (mm)',
y => 'Bill Depth (mm)'
```
Expand All @@ -38,8 +38,8 @@ SELECT bill_len, bill_dep, species, island FROM ggsql:penguins
VISUALISE bill_len AS x, bill_dep AS y
DRAW point
FACET species BY island
LABEL
title => 'Bill Dimensions by Species and Island',
TITLE
main => 'Bill Dimensions by Species and Island',
x => 'Bill Length (mm)',
y => 'Bill Depth (mm)'
```
Expand All @@ -53,8 +53,8 @@ SELECT bill_len, bill_dep, species FROM ggsql:penguins
VISUALISE bill_len AS x, bill_dep AS y
DRAW point
FACET species SETTING free => 'y'
LABEL
title => 'Bill Dimensions (Free Y Scale)',
TITLE
main => 'Bill Dimensions (Free Y Scale)',
x => 'Bill Length (mm)',
y => 'Bill Depth (mm)'
```
16 changes: 8 additions & 8 deletions doc/gallery/examples/histogram.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Histograms show the distribution of a numeric variable by grouping values into b
SELECT Temp FROM ggsql:airquality
VISUALISE Temp AS x
DRAW histogram
LABEL
title => 'Temperature Distribution',
TITLE
main => 'Temperature Distribution',
x => 'Temperature (F)',
y => 'Count'
```
Expand All @@ -37,8 +37,8 @@ SELECT Temp FROM ggsql:airquality
VISUALISE Temp AS x
DRAW histogram
SETTING bins => 15
LABEL
title => 'Temperature Distribution (15 bins)',
TITLE
main => 'Temperature Distribution (15 bins)',
x => 'Temperature (F)',
y => 'Count'
```
Expand All @@ -52,8 +52,8 @@ SELECT Temp FROM ggsql:airquality
VISUALISE Temp AS x
DRAW histogram
SETTING binwidth => 5
LABEL
title => 'Temperature Distribution (5 degree bins)',
TITLE
main => 'Temperature Distribution (5 degree bins)',
x => 'Temperature (F)',
y => 'Count'
```
Expand All @@ -67,8 +67,8 @@ SELECT Temp FROM ggsql:airquality
VISUALISE Temp AS x
DRAW histogram
REMAPPING density AS y
LABEL
title => 'Temperature Density',
TITLE
main => 'Temperature Density',
x => 'Temperature (F)',
y => 'Density'
```
10 changes: 5 additions & 5 deletions doc/gallery/examples/line-chart.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ SELECT Date, Temp FROM ggsql:airquality
VISUALISE Date AS x, Temp AS y
DRAW line
SCALE x VIA date
LABEL
title => 'Daily Temperature',
TITLE
main => 'Daily Temperature',
x => 'Date',
y => 'Temperature (F)'
```
Expand All @@ -27,7 +27,7 @@ LABEL
- `VISUALISE Date AS x, Temp AS y` maps the date column to x and temperature to y
- `DRAW line` connects data points with lines
- `SCALE x VIA date` ensures the x-axis is formatted as dates with appropriate tick marks (happens automatically if your database has a dedicated date type)
- `LABEL` provides descriptive titles for the chart and axes
- `TITLE` provides descriptive titles for the chart and axes

## Variations

Expand All @@ -40,8 +40,8 @@ SELECT Day, Temp, Month FROM ggsql:airquality
VISUALISE Day AS x, Temp AS y, Month AS color
DRAW line
SCALE ORDINAL color
LABEL
title => 'Daily Temperature by Month',
TITLE
main => 'Daily Temperature by Month',
x => 'Date',
y => 'Temperature (F)'
```
18 changes: 9 additions & 9 deletions doc/gallery/examples/minard.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ Now that we have all the data included in the ways we want, we can start detaili
The first thing we might do is to pick some better colours.
Because we have two levels for the `direction` variable —**A**dvance and **R**etreat— we can create a new colour scale for the `stroke` aesthetic.
We'll choose the colours to more closely resemble the original graphic by Minard.
We set the palette using the `TO` keyword, and format the labels using `RENAMING`.
We set the palette using the `TO` keyword, and format the labels using `LABEL`.

```{ggsql}
VISUALISE long AS x, lat AS y FROM 'minard_troops.csv'
DRAW path
MAPPING direction AS stroke, survivors AS linewidth
PARTITION BY direction, group
SCALE stroke TO ('burlywood', 'black')
RENAMING 'A' => 'Advance', 'R' => 'Retreat'
LABEL 'A' => 'Advance', 'R' => 'Retreat'
```

Now for a slightly more complicated scale, we're going to set one for the `linewidth` variable that represent the number of troops.
Expand All @@ -130,7 +130,7 @@ VISUALISE long AS x, lat AS y FROM 'minard_troops.csv'
MAPPING direction AS stroke, survivors AS linewidth
PARTITION BY direction, group
SCALE stroke TO ('burlywood', 'black')
RENAMING 'A' => 'Advance', 'R' => 'Retreat'
LABEL 'A' => 'Advance', 'R' => 'Retreat'
SCALE linewidth FROM (0, null) TO (0, 20)
```

Expand All @@ -154,12 +154,12 @@ VISUALISE long AS x, lat AS y FROM 'minard_troops.csv'
MAPPING city AS label FROM 'minard_cities.csv'
SETTING fontsize => 6
SCALE stroke TO ('burlywood', 'black')
RENAMING 'A' => 'Advance', 'R' => 'Retreat'
LABEL 'A' => 'Advance', 'R' => 'Retreat'
SCALE linewidth FROM (0, null) TO (0, 30)
```

An additional obvious way to polish your graphic is to add nicer titles for all your variables.
We can use the `LABEL` statement to add custom labels for our plot.
We can use the `TITLE` statement to add custom labels for our plot.
In the title, we escape the single quote mark by using `\'` so that we know it is not the end of the string yet.
Moreover, we can use `null` to note that a title should be removed.
In that way we can hide the `long` and `lat` labels from the position mapping.
Expand All @@ -173,11 +173,11 @@ VISUALISE long AS x, lat AS y FROM 'minard_troops.csv'
MAPPING city AS label FROM 'minard_cities.csv'
SETTING fontsize => 6
SCALE stroke TO ('burlywood', 'black')
RENAMING 'A' => 'Advance', 'R' => 'Retreat'
LABEL 'A' => 'Advance', 'R' => 'Retreat'
SCALE linewidth FROM (0, null) TO (0, 20)
LABEL
title => 'Napoleon\'s Russian Campaign',
subtitle => 'Inspired by the graphic of C.J. Minard',
TITLE
main => 'Napoleon\'s Russian Campaign',
sub => 'Inspired by the graphic of C.J. Minard',
linewidth => 'Troops',
stroke => 'Direction',
x => null,
Expand Down
12 changes: 6 additions & 6 deletions doc/gallery/examples/multi-layer.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ DRAW line
DRAW point
SETTING size => 4, color => 'darkblue'
SCALE x VIA date
LABEL
title => 'Temperature with Line and Points',
TITLE
main => 'Temperature with Line and Points',
x => 'Date',
y => 'Temperature (F)'
```
Expand All @@ -45,8 +45,8 @@ DRAW line
DRAW line
MAPPING Ozone AS y, 'Ozone' AS color
SCALE x VIA date
LABEL
title => 'Temperature and Ozone Over Time',
TITLE
main => 'Temperature and Ozone Over Time',
x => 'Date',
y => 'Value'
```
Expand All @@ -69,8 +69,8 @@ DRAW point
MAPPING Date AS x, value AS y, 'Ozone' AS color FROM ozone
SETTING size => 3
SCALE x VIA date
LABEL
title => 'Temperature vs Ozone',
TITLE
main => 'Temperature vs Ozone',
x => 'Date',
y => 'Value'
```
18 changes: 9 additions & 9 deletions doc/gallery/examples/scatterplot.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ This is one of the most fundamental visualization types for exploring correlatio
```{ggsql}
VISUALISE bill_len AS x, bill_dep AS y FROM ggsql:penguins
DRAW point
LABEL
title => 'Penguin Bill Dimensions',
TITLE
main => 'Penguin Bill Dimensions',
x => 'Bill Length (mm)',
y => 'Bill Depth (mm)'
```
Expand All @@ -25,7 +25,7 @@ LABEL
- `VISUALISE ... FROM ggsql:penguins` loads the built-in penguins dataset
- `bill_len AS x, bill_dep AS y` maps bill length to the x-axis and bill depth to the y-axis
- `DRAW point` creates a scatter plot using points
- `LABEL` adds descriptive axis labels and a title
- `TITLE` adds descriptive axis labels and a title

## Variations

Expand All @@ -36,8 +36,8 @@ We're adding `species AS color` to the mapping to colour the points by species.
```{ggsql}
VISUALISE bill_len AS x, bill_dep AS y, species AS color FROM ggsql:penguins
DRAW point
LABEL
title => 'Penguin Bill Dimensions by Species',
TITLE
main => 'Penguin Bill Dimensions by Species',
x => 'Bill Length (mm)',
y => 'Bill Depth (mm)'
```
Expand All @@ -48,8 +48,8 @@ The color palette can be changed by detailing the `SCALE color` clause.
VISUALISE bill_len AS x, bill_dep AS y, species AS color FROM ggsql:penguins
DRAW point
SCALE color TO ('DeepSkyBlue', 'Fuchsia', 'Lime')
LABEL
title => 'Penguin Bill Dimensions by Species',
TITLE
main => 'Penguin Bill Dimensions by Species',
x => 'Bill Length (mm)',
y => 'Bill Depth (mm)'
```
Expand All @@ -66,8 +66,8 @@ VISUALISE
island AS shape
FROM ggsql:penguins
DRAW point
LABEL
title => 'Penguin Bill Dimensions by Species',
TITLE
main => 'Penguin Bill Dimensions by Species',
x => 'Bill Length (mm)',
y => 'Bill Depth (mm)'
```
Expand Down
6 changes: 3 additions & 3 deletions doc/get_started/first_plot.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ The code below shows a simple ggsql example. But it is not just a static piece o
VISUALISE bill_len AS x, bill_dep AS y, species AS fill FROM ggsql:penguins
DRAW point
SCALE x
RENAMING * => '{} mm'
LABEL
title => 'Relationship between bill dimensions in 3 species of penguins',
LABEL * => '{} mm'
TITLE
main => 'Relationship between bill dimensions in 3 species of penguins',
x => 'Bill length',
y => 'Bill depth'
```
Expand Down
2 changes: 1 addition & 1 deletion doc/get_started/grammar.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Then you'll use `VISUALIZE` (or `VISUALISE` 🇬🇧) to switch from creating a
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 `SCALE`s, 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 `LABEL`s to explain your plot to others.
Finally you finish up by adding `TITLE`s 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.

In the end of this tutorial we will revisit the duality of the syntax and the grammar and also provide a [handy table](wrap_up.qmd#from-grammar-to-syntax) that shows how they relate to each other.
Loading
Loading