diff --git a/AGENTS.md b/AGENTS.md index f9897d61e..0c4908b4c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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 . 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. diff --git a/CHANGELOG.md b/CHANGELOG.md index a4ca132f1..b3ad6284a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/README.md b/README.md index 892964f34..10b72ddfe 100644 --- a/README.md +++ b/README.md @@ -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? diff --git a/doc/_quarto.yml b/doc/_quarto.yml index fb298d88c..a3296ce46 100644 --- a/doc/_quarto.yml +++ b/doc/_quarto.yml @@ -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`" @@ -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`" diff --git a/doc/faq.qmd b/doc/faq.qmd index 3a3dbb8ad..3bb561ba8 100644 --- a/doc/faq.qmd +++ b/doc/faq.qmd @@ -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)' ``` diff --git a/doc/gallery/examples/bar-chart.qmd b/doc/gallery/examples/bar-chart.qmd index 528cc0e9c..d67e325f5 100644 --- a/doc/gallery/examples/bar-chart.qmd +++ b/doc/gallery/examples/bar-chart.qmd @@ -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' ``` @@ -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' ``` @@ -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' ``` diff --git a/doc/gallery/examples/faceted.qmd b/doc/gallery/examples/faceted.qmd index 00afd5684..8a59822f0 100644 --- a/doc/gallery/examples/faceted.qmd +++ b/doc/gallery/examples/faceted.qmd @@ -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)' ``` @@ -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)' ``` @@ -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)' ``` diff --git a/doc/gallery/examples/histogram.qmd b/doc/gallery/examples/histogram.qmd index fa0b6697a..4700ec1e2 100644 --- a/doc/gallery/examples/histogram.qmd +++ b/doc/gallery/examples/histogram.qmd @@ -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' ``` @@ -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' ``` @@ -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' ``` @@ -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' ``` diff --git a/doc/gallery/examples/line-chart.qmd b/doc/gallery/examples/line-chart.qmd index 0558336e8..e03a6f3e4 100644 --- a/doc/gallery/examples/line-chart.qmd +++ b/doc/gallery/examples/line-chart.qmd @@ -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)' ``` @@ -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 @@ -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)' ``` diff --git a/doc/gallery/examples/minard.qmd b/doc/gallery/examples/minard.qmd index 4a9e1e2a2..c1887aa99 100644 --- a/doc/gallery/examples/minard.qmd +++ b/doc/gallery/examples/minard.qmd @@ -107,7 +107,7 @@ 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' @@ -115,7 +115,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' ``` Now for a slightly more complicated scale, we're going to set one for the `linewidth` variable that represent the number of troops. @@ -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) ``` @@ -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. @@ -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, diff --git a/doc/gallery/examples/multi-layer.qmd b/doc/gallery/examples/multi-layer.qmd index bdc99ee23..824ca8fd8 100644 --- a/doc/gallery/examples/multi-layer.qmd +++ b/doc/gallery/examples/multi-layer.qmd @@ -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)' ``` @@ -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' ``` @@ -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' ``` diff --git a/doc/gallery/examples/scatterplot.qmd b/doc/gallery/examples/scatterplot.qmd index 2cc33f771..c48b4c806 100644 --- a/doc/gallery/examples/scatterplot.qmd +++ b/doc/gallery/examples/scatterplot.qmd @@ -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)' ``` @@ -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 @@ -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)' ``` @@ -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)' ``` @@ -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)' ``` diff --git a/doc/get_started/first_plot.qmd b/doc/get_started/first_plot.qmd index 39219973e..288c7b6fe 100644 --- a/doc/get_started/first_plot.qmd +++ b/doc/get_started/first_plot.qmd @@ -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' ``` diff --git a/doc/get_started/grammar.qmd b/doc/get_started/grammar.qmd index b760f7138..4798386d3 100644 --- a/doc/get_started/grammar.qmd +++ b/doc/get_started/grammar.qmd @@ -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. diff --git a/doc/get_started/the_rest.qmd b/doc/get_started/the_rest.qmd index 4bdfa7894..d134cdc20 100644 --- a/doc/get_started/the_rest.qmd +++ b/doc/get_started/the_rest.qmd @@ -43,13 +43,13 @@ Faceting is applied with the [`FACET`](../syntax/clause/facet.qmd) clause. It al There is an alternative to using the `FACET` variable, which is to map the variables directly to the facet aesthetics. There are three of these: `panel` is used when faceting by a single variable and `row` and `column` is used when faceting by two variables. `FACET var` is thus equivalent to `VISUALISE var AS panel`. Whichever you choose to use is thus a matter of personal preference, as well as whether you also need to modify faceting behavior (in which case you'd need a `FACET` clause anyway). -### `LABEL` -ggsql automatically labels the axes and legends in your plot by the column name of the data mapped to it. However, you often want to provide more descriptive names as well as a title to give context to the plot. All of this is accomplished with the [`LABEL`](../syntax/clause/label.qmd) clause by setting the label text for both titles, subtitles, etc. as well as any -aesthetic you have mapped. A `LABEL` clause may end up looking like this: +### `TITLE` +ggsql automatically labels the axes and legends in your plot by the column name of the data mapped to it. However, you often want to provide more descriptive names as well as a title to give context to the plot. All of this is accomplished with the [`TITLE`](../syntax/clause/title.qmd) clause by setting the label text for both titles, subtitles, etc. as well as any +aesthetic you have mapped. A `TITLE` clause may end up looking like this: ```ggsql -LABEL - title => "Average wingspan of a cartoon owl" +TITLE + main => "Average wingspan of a cartoon owl" x => "Radius of first circle (cm)" y => "Wingspan (cm)" ``` @@ -105,7 +105,7 @@ SCALE panel FROM ('Biscoe', 'Dream') Above, we use the `free` parameter of facet to allow each facet to have their own angle scale. Further, we use `SCALE` on the panel aesthetic to only show panels for the Biscoe and Dream islands. -We can use `LABEL` to add a bit more context to our final plot: +We can use `TITLE` to add a bit more context to our final plot: ```{ggsql} VISUALISE species AS fill FROM ggsql:penguins @@ -114,9 +114,9 @@ PROJECT TO polar FACET island SETTING free => 'angle' SCALE panel FROM ('Biscoe', 'Dream') -LABEL - title => 'Distribution of penguin species between islands', - subtitle => 'Compared across 344 penguins', +TITLE + main => 'Distribution of penguin species between islands', + sub => 'Compared across 344 penguins', fill => 'Species' ``` diff --git a/doc/ggsql.xml b/doc/ggsql.xml index b7376fe7b..90de554f3 100644 --- a/doc/ggsql.xml +++ b/doc/ggsql.xml @@ -98,7 +98,7 @@ FILTER ORDER PARTITION - RENAMING + LABEL TO VIA OVER @@ -247,10 +247,10 @@ clip - - - title - subtitle + + + main + sub caption tag @@ -389,7 +389,7 @@ - + @@ -437,7 +437,7 @@ - + @@ -478,7 +478,7 @@ - + @@ -518,7 +518,7 @@ - + @@ -536,12 +536,13 @@ + + + - - - @@ -565,7 +566,7 @@ - + @@ -609,7 +610,7 @@ - + @@ -623,7 +624,7 @@ - + @@ -638,8 +639,8 @@ - - + + @@ -652,7 +653,7 @@ - + @@ -663,8 +664,8 @@ - - + + @@ -687,7 +688,7 @@ - + @@ -725,7 +726,7 @@ - + @@ -766,7 +767,7 @@ - + @@ -777,9 +778,9 @@ - + - + @@ -792,7 +793,7 @@ - + @@ -818,7 +819,7 @@ - + diff --git a/doc/index.qmd b/doc/index.qmd index 789aef19e..6d7110caf 100644 --- a/doc/index.qmd +++ b/doc/index.qmd @@ -47,8 +47,8 @@ DRAW point PLACE rule SETTING slope => 0.4, y => -1 SCALE BINNED fill -LABEL - title => 'Relationship between bill dimensions in 3 species of penguins', +TITLE + main => 'Relationship between bill dimensions in 3 species of penguins', x => 'Bill length (mm)', y => 'Bill depth (mm)' ``` diff --git a/doc/syntax/clause/facet-tabulate.qmd b/doc/syntax/clause/facet-tabulate.qmd index 841eaa427..9e2806881 100644 --- a/doc/syntax/clause/facet-tabulate.qmd +++ b/doc/syntax/clause/facet-tabulate.qmd @@ -73,7 +73,7 @@ Note that `missing => 'drop'` has priority over any relabeling in `FORMAT`. ```{ggsql} TABULATE * FROM my_data FACET sex -FORMAT sex RENAMING null => 'unknown' +FORMAT sex LABEL null => 'unknown' ``` Place grouping labels in rows above their members. @@ -91,7 +91,7 @@ FACET species, island ``` The labels from multiple groups can be collapsed to a single stub column (or single rows) by using the `separator` setting to join the labels. -Labels are joined after `FORMAT RENAMING` is applied. +Labels are joined after `FORMAT LABEL` is applied. ```{ggsql} TABULATE * FROM my_data @@ -99,11 +99,11 @@ FACET species, island SETTING separator => ' - ' ``` -When group labels are placed in the stub, the labels can be controlled by `LABEL`. +When group labels are placed in the stub, the labels can be controlled by `TITLE`. In case of `separator`-joined labels, the first variable (`species` in the example) displays the label. ```{ggsql} TABULATE * FROM my_data FACET species, island -LABEL island => 'Place', species => 'Type' +TITLE island => 'Place', species => 'Type' ``` diff --git a/doc/syntax/clause/facet.qmd b/doc/syntax/clause/facet.qmd index 4db512700..66ee2b1c4 100644 --- a/doc/syntax/clause/facet.qmd +++ b/doc/syntax/clause/facet.qmd @@ -47,12 +47,12 @@ This clause behaves much like the `SETTINGS` clause in `DRAW`, in that it allows When you apply faceting to a plot you are creating new aesthetics you can control. For 1-dimensional faceting (no `BY` clause) the aesthetic is called `panel` and for 2-dimensional faceting the aesthetics are called `row` and `column`. You can read more about these aesthetics in [their documentation](../scale/aesthetic/Z_faceting.qmd) ### Customizing facet strip labels -To customize facet strip labels (e.g., renaming categories), use the `RENAMING` clause on the facet scale: +To customize facet strip labels (e.g., renaming categories), use the `LABEL` subclause on the facet scale: ```ggsql FACET region SCALE panel - RENAMING 'N' => 'North', 'S' => 'South' + LABEL 'N' => 'North', 'S' => 'South' ``` See the [facet scale documentation](../scale/aesthetic/Z_faceting.qmd) for more details on label customization. diff --git a/doc/syntax/clause/format.qmd b/doc/syntax/clause/format.qmd index ac657c6b5..350b2c983 100644 --- a/doc/syntax/clause/format.qmd +++ b/doc/syntax/clause/format.qmd @@ -11,7 +11,7 @@ It is the workhorse for column-focussed changes: value formatting, display prope FORMAT [ANY | BODY | STUB] (* | , ...) SETTING => , ... - RENAMING => , ... + LABEL => , ... ``` ## Target @@ -83,24 +83,24 @@ Unset, the default depends on the column: right-aligned for numbers and stub col ## Renaming ```ggsql -RENAMING => , ... +LABEL => , ... ``` -The `RENAMING` clause is *the* place to format the cell contents. -It works the same as the namesake in the [`SCALE`](scale.qmd#renaming) clause. -Generally, it works not unlike the [`LABEL`](label-tabulate.qmd) clause in the sense that you specify a cell's content on the left and a replacement value on the right. +The `LABEL` subclause is *the* place to format the cell contents. +It works the same as the namesake in the [`SCALE`](scale.qmd#label) clause. +Generally, it works not unlike the [`TITLE`](title-tabulate.qmd) clause in the sense that you specify a cell's content on the left and a replacement value on the right. Alternatively, you can use a formatter with the `* => '...'` syntax. Specifically see the [break formatting](scale.qmd#break-formatting) section for a list of formatters. ```ggsql -- Replace a specific piece of content -FORMAT species RENAMING 'adelie' => 'Pygoscelis adeliae' +FORMAT species LABEL 'adelie' => 'Pygoscelis adeliae' -- Suppress/hide a specific piece of content -FORMAT species RENAMING 'adelie' => null +FORMAT species LABEL 'adelie' => null -- Format all cells in the column as lower-case -FORMAT species RENAMING * => '{:lower}' +FORMAT species LABEL * => '{:lower}' ``` ## Examples @@ -115,12 +115,12 @@ TABULATE * FROM my_data ``` Stubheads, the column labels for stub columns, are hidden by default. -To display these, you can use the `LABEL` clause. +To display these, you can use the `TITLE` clause. ```{ggsql} TABULATE * FROM my_data FORMAT STUB island - LABEL island => 'Island' + TITLE island => 'Island' ``` Stub columns cannot be targetted by spans. The boundary between stub and body is un-spannable. @@ -162,7 +162,7 @@ Replace null values everywhere by selecting all columns. ```{ggsql} TABULATE * FROM my_data - FORMAT * RENAMING null => '---' + FORMAT * LABEL null => '---' ``` Replacing specific pieces of content. @@ -170,7 +170,7 @@ Replacing specific pieces of content. ```{ggsql} TABULATE * FROM my_data FORMAT body_mass, sex - RENAMING + LABEL null => '?', 'male' => 'β™‚', 'female' => '♀' @@ -181,5 +181,5 @@ Using a formatter to target all cells in a column. ```{ggsql} TABULATE * FROM my_data FORMAT body_mass - RENAMING * => '{:num %.0f}g' + LABEL * => '{:num %.0f}g' ``` diff --git a/doc/syntax/clause/scale.qmd b/doc/syntax/clause/scale.qmd index b5b1450b3..6b1777c87 100644 --- a/doc/syntax/clause/scale.qmd +++ b/doc/syntax/clause/scale.qmd @@ -8,7 +8,7 @@ Scales are an important concept in ggsql. While DRAW clauses define what to draw The `SCALE` clause takes a number of subclauses, all of them optional: ```ggsql SCALE FROM TO VIA - SETTING => , ... RENAMING => + SETTING => , ... LABEL => , ... ``` The `type` defines the class of scale to use. It can be one of five different types: @@ -52,12 +52,12 @@ SETTING => , ... This clause behaves much like the `SETTINGS` clause in `DRAW`, in that it allows you to fine-tune specific behavior of the scale. Permissible settings depends on the scale type and are documented there. -### `RENAMING` +### `LABEL` ```ggsql -RENAMING => , ... +LABEL => , ... ``` -This clause works much like the `LABEL` clause but works on the break names of the scale. The general syntax is that you provide the name of the break on the left and what it should appear as on the right, e.g `'adelie' => 'Pygoscelis adeliae'`. The clause is understood as a look-up table in the sense that if you provide a renaming for a break that doesn't appear in the scale then nothing will happen and if a break exists but doesn't have a renaming defined it will go through unaltered. To suppress the label of a specific break you can rename it to `null`, e.g. `'adelie' => null`. This will not remove the break, only the label. +This clause works much like the `TITLE` clause but works on the break names of the scale. The general syntax is that you provide the name of the break on the left and what it should appear as on the right, e.g `'adelie' => 'Pygoscelis adeliae'`. The subclause is understood as a look-up table in the sense that if you provide a renaming for a break that doesn't appear in the scale then nothing will happen and if a break exists but doesn't have a renaming defined it will go through unaltered. To suppress the label of a specific break you can rename it to `null`, e.g. `'adelie' => null`. This will not remove the break, only the label. #### Break formatting Apart from the direct renaming described above it is also possible to provide a formatting function to be applied to all breaks. The syntax for this is `* => '...'` with the content of the string on the right being a string interpolation format. The basic syntax for this is that the break value will be inserted into any place where `{}` appears. This means that e.g. `* => '{} species'` will result in the label "adelie species" for the break "adelie". Besides simply inserting the value as-is, it is also possible to apply a formatter to the label before insertion by naming a formatter inside the curly braces prefixed with `:`. Known formatters are: diff --git a/doc/syntax/clause/span.qmd b/doc/syntax/clause/span.qmd index aa1d990a6..2f46c7845 100644 --- a/doc/syntax/clause/span.qmd +++ b/doc/syntax/clause/span.qmd @@ -37,11 +37,11 @@ The identifier can be these values: * An identifier with double-quotes or backtick-quotes, depending on the backend * `null` -A spanner can also be labelled using the [`LABEL`](label-tabulate.qmd) clause, using the span identifier as key. +A spanner can also be labelled using the [`TITLE`](title-tabulate.qmd) clause, using the span identifier as key. This is the preferred method if the label contains exotic symbols that are not allowed in identifiers. A spanner identifier can **not** be the same as a column name. -If you want to display the same label as a column name, you can use the [`LABEL`](label-tabulate.qmd) clause too. +If you want to display the same label as a column name, you can use the [`TITLE`](title-tabulate.qmd) clause too. Giving `null` as identifier makes an anonymous spanner for the side-effect of ordering columns. Anonymous spanners do not render labels. @@ -107,12 +107,12 @@ TABULATE * FROM my_data SPAN Lengths OVER Bill, flipper_len ``` -The `LABEL` clause can be used for complex labels. +The `TITLE` clause can be used for complex labels. ```{ggsql} TABULATE * FROM my_data SPAN Bill OVER bill_len, bill_dep - LABEL Bill => '🐧 bills' + TITLE Bill => '🐧 bills' ``` Anonymous spanners can be used to reorder columns. diff --git a/doc/syntax/clause/tabulate.qmd b/doc/syntax/clause/tabulate.qmd index 2a370e021..388e6bab5 100644 --- a/doc/syntax/clause/tabulate.qmd +++ b/doc/syntax/clause/tabulate.qmd @@ -32,9 +32,9 @@ The columns can be selected in (a mixture of) one of three forms: Without the `*` wildcard, only the listed columns are kept. The wildcard can be combined with explicit columns to partially order columns, where the wildcard becomes all implicit columns. -When a column is renamed using the `AS` keyword, other table clauses --- like `LABEL`, `SPAN` and `FORMAT` --- use the *new* name. +When a column is renamed using the `AS` keyword, other table clauses --- like `TITLE`, `SPAN` and `FORMAT` --- use the *new* name. Please note that renaming a column consumes the original, to avoid unintentional duplication. -It is discouraged to name column `title`, `subtitle` or `caption` as these are keywords in the [`LABEL`](label-tabulate.qmd) clause. +It is discouraged to name column `main`, `sub` or `caption` as these are keywords in the [`TITLE`](title-tabulate.qmd) clause. ```ggsql -- Select all columns @@ -92,7 +92,7 @@ Reordering columns TABULATE island, *, species FROM my_data ``` -Renaming columns on the fly. For order-preserving renames, see [`LABEL`](label-tabulate.qmd) clause. +Renaming columns on the fly. For order-preserving renames, see [`TITLE`](title-tabulate.qmd) clause. ```{ggsql} TABULATE diff --git a/doc/syntax/clause/label-tabulate.qmd b/doc/syntax/clause/title-tabulate.qmd similarity index 57% rename from doc/syntax/clause/label-tabulate.qmd rename to doc/syntax/clause/title-tabulate.qmd index 210ab5f0a..cf956a023 100644 --- a/doc/syntax/clause/label-tabulate.qmd +++ b/doc/syntax/clause/title-tabulate.qmd @@ -1,28 +1,30 @@ --- -title: "Define different titles with `LABEL`" +title: "Define different titles with `TITLE`" +aliases: + - /syntax/clause/label-tabulate.html --- ::: {.callout-note} -This page is about the `TABULATE` usage of the `LABEL` clause. -For the `VISUALISE` usage, see [this page](label.qmd). +This page is about the `TABULATE` usage of the `TITLE` clause. +For the `VISUALISE` usage, see [this page](title.qmd). ::: -The `LABEL` clause is a straightforward clause allowing you to override the default naming of column labels, spans, (sub)titles and captions. +The `TITLE` clause is a straightforward clause allowing you to override the default naming of column labels, spans, (sub)titles and captions. Unlike `VISUALISE`'s usage, there is no automatic labelling: a column with no label keeps its name as header. ## Clause syntax -The `LABEL` clause requires a comma-separated list of key-value pairs +The `TITLE` clause requires a comma-separated list of key-value pairs ```ggsql -LABEL => , ... +TITLE => , ... ``` On the left hand side of the arrow, the following keys can be used: * Column names as they occur in the data * Reserved keywords for special labels: - * `title` as the main title - * `subtitle` as the subtitle + * `main` as the main title + * `sub` as the subtitle * `caption` as the table caption * Spanner IDs declared by `SPAN` clauses. @@ -33,49 +35,49 @@ The support of rich text in tables is planned but not yet implemented. ## Examples -Unlike using aliases in `TABULATE`, the `LABEL` clause lets you change column labels without changing column order +Unlike using aliases in `TABULATE`, the `TITLE` clause lets you change column labels without changing column order ```{ggsql} CREATE TEMP TABLE my_data AS SELECT * FROM ggsql:penguins LIMIT 5 TABULATE * FROM my_data - LABEL bill_len => 'Bill length', bill_dep => 'Bill depth' + TITLE bill_len => 'Bill length', bill_dep => 'Bill depth' ``` Hiding labels. ```{ggsql} TABULATE * FROM my_data - LABEL island => null, species => null + TITLE island => null, species => null ``` Adding titles to a table. ```{ggsql} TABULATE * FROM my_data - LABEL - title => 'Penguins!', - subtitle => 'Structural size measurements', + TITLE + main => 'Penguins!', + sub => 'Structural size measurements', caption => 'Source: Palmer station, Antarctica' ``` When column names and reserved keywords compete for a label, the reserved keyword wins. ```{ggsql} --- data has column named 'title' +-- data has column named 'main' CREATE TEMP TABLE title_data AS -SELECT * FROM (VALUES (1, 'a'), (2, 'b'), (3, 'c')) AS t(id, title) +SELECT * FROM (VALUES (1, 'a'), (2, 'b'), (3, 'c')) AS t(id, main) TABULATE * FROM title_data - LABEL - title => 'Overrules column' + TITLE + main => 'Overrules column' ``` You can target an aliased column instead. ```{ggsql} -TABULATE *, title AS title_col FROM title_data - LABEL - title => 'Main title', - title_col => 'Column title' -``` \ No newline at end of file +TABULATE *, main AS main_col FROM title_data + TITLE + main => 'Main title', + main_col => 'Column title' +``` diff --git a/doc/syntax/clause/label.qmd b/doc/syntax/clause/title.qmd similarity index 74% rename from doc/syntax/clause/label.qmd rename to doc/syntax/clause/title.qmd index 766f3d4b8..7474c1a6e 100644 --- a/doc/syntax/clause/label.qmd +++ b/doc/syntax/clause/title.qmd @@ -1,31 +1,33 @@ --- -title: "Define different titles with `LABEL`" +title: "Define different titles with `TITLE`" +aliases: + - /syntax/clause/label.html --- ::: {.callout-note} -This page is about the `VISUALISE` usage of the `LABEL` clause. -For the `TABULATE` usage, see [this page](label-tabulate.qmd). +This page is about the `VISUALISE` usage of the `TITLE` clause. +For the `TABULATE` usage, see [this page](title-tabulate.qmd). ::: -The `LABEL` clause is one of the simpler clauses in ggsql and allows you to override the default naming of axes and legends, as well as adding titles to the plot. +The `TITLE` clause is one of the simpler clauses in ggsql and allows you to override the default naming of axes and legends, as well as adding titles to the plot. ## Clause syntax -The `LABEL` clause takes one or more labeling settings. +The `TITLE` clause takes one or more labeling settings. ```ggsql -LABEL => , ... +TITLE => , ... ``` If an `aesthetic` is given, then the title will be used for the relevant axis or legend, e.g. `x => 'my x-axis'` will label the x axis, whereas `fill => 'Species'` will label the legend for fill (if any). There are a few additional labels beside the aesthetics that govern the different titles of the plot and can be given instead of an aesthetic name: -* `title`: The main title of the plot -* `subtitle`: An additional, often longer and more descriptive, title beneath the main title +* `main`: The main title of the plot +* `sub`: An additional, often longer and more descriptive, title beneath the main title * `caption`: A string placed below the plot, often used to add additional information about the data source etc. Supported by every writer except Vega-Lite, which has no equivalent. ## Rich text -Every writer except Vega-Lite interprets the strings you provide here as markdown, so `LABEL title => 'Sales in **2024**'` renders the year in bold. +Every writer except Vega-Lite interprets the strings you provide here as markdown, so `TITLE main => 'Sales in **2024**'` renders the year in bold. This applies to the plot title, subtitle and caption, to the axis and legend titles, and to break labels (axis tick labels and legend keys). The Vega-Lite writer has no rich-text support at all and draws every label exactly as given. @@ -39,7 +41,7 @@ Axes and legends get an automatic label from the mapping. The logic is as follow 1. Start from the global mapping and then go through the layer mappings as they appear. 2. Collect mappings for each aesthetic in the order they appear 3. For each aesthetic determine the label based on the following priority: - 1. An explicitly provided one with `LABEL` + 1. An explicitly provided one with `TITLE` 2. The name of the first appearing column mapping 3. The name of the aesthetic diff --git a/doc/syntax/index.qmd b/doc/syntax/index.qmd index f00a94101..7f78d5c7a 100644 --- a/doc/syntax/index.qmd +++ b/doc/syntax/index.qmd @@ -11,12 +11,12 @@ ggsql augments the standard SQL syntax with a number of new clauses to describe - [`SCALE`](clause/scale.qmd) specifies how an aesthetic should be scaled - [`FACET`](clause/facet.qmd) describes how data should be split into small multiples - [`PROJECT`](clause/project.qmd) is used for selecting the coordinate system to use -- [`LABEL`](clause/label.qmd) is used to manually add titles to the plot or the various axes and legends +- [`TITLE`](clause/title.qmd) is used to manually add titles to the plot or the various axes and legends ## Table clauses - [`TABULATE`](clause/tabulate.qmd) initialises the table part of the query -- [`LABEL`](clause/label-tabulate.qmd) is used to manually change column labels and titles +- [`TITLE`](clause/title-tabulate.qmd) is used to manually change column labels and titles - [`SPAN`](clause/span.qmd) can be used to group columns and display a label across them - [`FORMAT`](clause/format.qmd) declares formatting for columns - [`FACET`](clause/facet-tabulate.qmd) enables row-grouping operations on tables diff --git a/doc/syntax/scale/aesthetic/0_position.qmd b/doc/syntax/scale/aesthetic/0_position.qmd index 790a9000c..621880651 100644 --- a/doc/syntax/scale/aesthetic/0_position.qmd +++ b/doc/syntax/scale/aesthetic/0_position.qmd @@ -29,4 +29,4 @@ The recognized suffixes are: Which version of an aesthetic to use depends on the layer. All aesthetics within a family use the same scale, which is named after its primary aesthetic. -This means that even when rendering a layer that only uses `xmin` and `xmax`, you will still scale it by writing `SCALE x ...` and label it by writing `LABEL x => ...` +This means that even when rendering a layer that only uses `xmin` and `xmax`, you will still scale it by writing `SCALE x ...` and label it by writing `TITLE x => ...` diff --git a/doc/syntax/scale/aesthetic/Z_faceting.qmd b/doc/syntax/scale/aesthetic/Z_faceting.qmd index 7bb4e0a67..478903f7b 100644 --- a/doc/syntax/scale/aesthetic/Z_faceting.qmd +++ b/doc/syntax/scale/aesthetic/Z_faceting.qmd @@ -24,12 +24,12 @@ SCALE x ``` In order to show data where the facet variable is null, it is necessary to explicitly include `null` in the input range of a facet aesthetic scale. -Just like discrete position aesthetics. You can also use `RENAMING` on the scale to customize facet strip labels. +Just like discrete position aesthetics. You can also use `LABEL` on the scale to customize facet strip labels. ```{ggsql} VISUALISE sex AS x FROM ggsql:penguins DRAW bar FACET species SCALE panel FROM ('Adelie', null) - RENAMING null => 'The rest' + LABEL null => 'The rest' ``` diff --git a/doc/syntax/scale/type/binned.qmd b/doc/syntax/scale/type/binned.qmd index 1b35ce686..6e760d43e 100644 --- a/doc/syntax/scale/type/binned.qmd +++ b/doc/syntax/scale/type/binned.qmd @@ -145,18 +145,18 @@ SCALE BINNED x ``` ## Renaming -Breaks are generally named by their value. However, you may wish to rename one, several, or all of these. The `RENAMING` clause allows you to do that both by directly renaming a specific break or by providing a formatting function. +Breaks are generally named by their value. However, you may wish to rename one, several, or all of these. The `LABEL` subclause allows you to do that both by directly renaming a specific break or by providing a formatting function. ### Direct renaming -When you provide a break value on the left and a break exists at that value then it will take on the label specified on the right. For example adding `RENAMING 0 => 'Nil'` will ensure that if there is a break at 0 it will appear as "Nil" on the legend/axis +When you provide a break value on the left and a break exists at that value then it will take on the label specified on the right. For example adding `LABEL 0 => 'Nil'` will ensure that if there is a break at 0 it will appear as "Nil" on the legend/axis ### Label formatting -Besides direct renaming you can also provide a formatting string if you want the same to happen to all labels, e.g. add a prefix or suffix. The syntax for this is `RENAMING * => '... {} ...'`. The current label will be inserted into the `{}` to produce the new label. Besides simply inserting the break value into the string, we can also provide a formatter. Of special interest to binned scales are the `:time` and `:num` formatters which lets you control how temporal and numeric values are presented. You can read more about these formatters in [the break formatting section of the `SCALE` documentation](../../clause/scale.qmd#break-formatting) +Besides direct renaming you can also provide a formatting string if you want the same to happen to all labels, e.g. add a prefix or suffix. The syntax for this is `LABEL * => '... {} ...'`. The current label will be inserted into the `{}` to produce the new label. Besides simply inserting the break value into the string, we can also provide a formatter. Of special interest to binned scales are the `:time` and `:num` formatters which lets you control how temporal and numeric values are presented. You can read more about these formatters in [the break formatting section of the `SCALE` documentation](../../clause/scale.qmd#break-formatting) You can combine formatting with direct renaming in which case the direct renaming has priority over the formatting. ### Labels in binned legends -With some writers the legend for binned scales looks like the standard legend but with the label showing the range of the bin. In these situations the renaming is applied before the range label is being created. For example, if you have a `RENAMING 0 => 'zero'`, then the final label will become "zero – 10" (assuming the upper end of the bin is 10). There is currently no way to take control over the format of the range label. +With some writers the legend for binned scales looks like the standard legend but with the label showing the range of the bin. In these situations the renaming is applied before the range label is being created. For example, if you have a `LABEL 0 => 'zero'`, then the final label will become "zero – 10" (assuming the upper end of the bin is 10). There is currently no way to take control over the format of the range label. If `oob => 'squish'` then the terminal labels are formatted as e.g. "β‰₯ 10" to reflect the terminal bins are open-ended. It still applies that the renaming is applied before constructing the final label @@ -168,7 +168,7 @@ If `oob => 'squish'` then the terminal labels are formatted as e.g. "β‰₯ 10" to VISUALISE bill_dep AS x FROM ggsql:penguins DRAW bar SCALE BINNED x - RENAMING 20 => 'Twenty' + LABEL 20 => 'Twenty' ``` #### Adding suffix to break labels @@ -177,7 +177,7 @@ SCALE BINNED x VISUALISE bill_dep AS x FROM ggsql:penguins DRAW bar SCALE BINNED x - RENAMING * => '{} mm' + LABEL * => '{} mm' ``` #### Using a formatter to control number formats @@ -186,5 +186,5 @@ SCALE BINNED x VISUALISE bill_dep AS x FROM ggsql:penguins DRAW bar SCALE BINNED x - RENAMING * => '{:num %.1f}' + LABEL * => '{:num %.1f}' ``` diff --git a/doc/syntax/scale/type/continuous.qmd b/doc/syntax/scale/type/continuous.qmd index 19cc1fdb6..ee6ac8011 100644 --- a/doc/syntax/scale/type/continuous.qmd +++ b/doc/syntax/scale/type/continuous.qmd @@ -95,7 +95,7 @@ If not provided explicitly by the user the breaks for the scales will be calcula - `pretty => false`: Linear spacing in integer space as close to the requested number of breaks ### Minor breaks -Minor breaks are the unlabelled sub-divisions between two breaks β€” drawn as shorter ticks and fainter gridlines. They carry no labels, so unlike `breaks` they are never affected by `RENAMING` or a label template. +Minor breaks are the unlabelled sub-divisions between two breaks β€” drawn as shorter ticks and fainter gridlines. They carry no labels, so unlike `breaks` they are never affected by `LABEL` or a label template. Where `breaks => 5` asks for about five breaks across the whole scale, `minor_breaks => 3` asks for three minor breaks *inside each interval between two breaks*. @@ -207,13 +207,13 @@ SCALE x ``` ## Renaming -Breaks are generally named by their value. However, you may wish to rename one, several, or all of these. The `RENAMING` clause allows you to do that both by directly renaming a specific break or by providing a formatting function. +Breaks are generally named by their value. However, you may wish to rename one, several, or all of these. The `LABEL` subclause allows you to do that both by directly renaming a specific break or by providing a formatting function. ### Direct renaming -When you provide a break value on the left and a break exists at that value then it will take on the label specified on the right. For example adding `RENAMING 0 => 'Nil'` will ensure that if there is a break at 0 it will appear as "Nil" on the legend/axis +When you provide a break value on the left and a break exists at that value then it will take on the label specified on the right. For example adding `LABEL 0 => 'Nil'` will ensure that if there is a break at 0 it will appear as "Nil" on the legend/axis ### Label formatting -Besides direct renaming you can also provide a formatting string if you want the same to happen to all labels, e.g. add a prefix or suffix. The syntax for this is `RENAMING * => '... {} ...'`. The current label will be inserted into the `{}` to produce the new label. Besides simply inserting the break value into the string, we can also provide a formatter. Of special interest to continuous scales are the `:time` and `:num` formatters which lets you control how temporal and numeric values are presented. You can read more about these formatters in [the break formatting section of the `SCALE` documentation](../../clause/scale.qmd#break-formatting) +Besides direct renaming you can also provide a formatting string if you want the same to happen to all labels, e.g. add a prefix or suffix. The syntax for this is `LABEL * => '... {} ...'`. The current label will be inserted into the `{}` to produce the new label. Besides simply inserting the break value into the string, we can also provide a formatter. Of special interest to continuous scales are the `:time` and `:num` formatters which lets you control how temporal and numeric values are presented. You can read more about these formatters in [the break formatting section of the `SCALE` documentation](../../clause/scale.qmd#break-formatting) You can combine formatting with direct renaming in which case the direct renaming has priority over the formatting. @@ -225,7 +225,7 @@ You can combine formatting with direct renaming in which case the direct renamin VISUALISE bill_len AS x, bill_dep AS y FROM ggsql:penguins DRAW point SCALE x - RENAMING 50 => 'Fifty' + LABEL 50 => 'Fifty' ``` #### Adding suffix to break labels @@ -234,7 +234,7 @@ SCALE x VISUALISE bill_len AS x, bill_dep AS y FROM ggsql:penguins DRAW point SCALE x - RENAMING * => '{} mm' + LABEL * => '{} mm' ``` #### Using a formatter to control temporal formats @@ -243,7 +243,7 @@ SCALE x VISUALISE Date AS x, Temp AS y FROM ggsql:airquality DRAW line SCALE x - RENAMING * => '{:time %B}' + LABEL * => '{:time %B}' ``` #### Using a formatter to control number formats @@ -252,5 +252,5 @@ SCALE x VISUALISE bill_len AS x, bill_dep AS y FROM ggsql:penguins DRAW point SCALE x - RENAMING * => '{:num %.3e}' + LABEL * => '{:num %.3e}' ``` diff --git a/doc/syntax/scale/type/discrete.qmd b/doc/syntax/scale/type/discrete.qmd index 63d76c9cf..146832fcf 100644 --- a/doc/syntax/scale/type/discrete.qmd +++ b/doc/syntax/scale/type/discrete.qmd @@ -88,13 +88,13 @@ SCALE color FROM ('Adelie', 'Chinstrap', 'Gentoo') ``` ## Renaming -Breaks are generally named by their value. However, you may wish to rename one, several, or all of these. The `RENAMING` clause allows you to do that both by directly renaming a specific break or by providing a formatting function. +Breaks are generally named by their value. However, you may wish to rename one, several, or all of these. The `LABEL` subclause allows you to do that both by directly renaming a specific break or by providing a formatting function. ### Direct renaming -When you provide a break value on the left and a break exists at that value then it will take on the label specified on the right. For example adding RENAMING 'Adelie' => 'AdΓ©lie' will ensure that the species name will get the correct diacrit in the label. +When you provide a break value on the left and a break exists at that value then it will take on the label specified on the right. For example adding LABEL 'Adelie' => 'AdΓ©lie' will ensure that the species name will get the correct diacrit in the label. ### Label formatting -Besides direct renaming you can also provide a formatting string if you want the same to happen to all labels, e.g. add a prefix or suffix. The syntax for this is `RENAMING * => '... {} ...'`. The current label will be inserted into the `{}` to produce the new label. Besides simply inserting the break value into the string, we can also provide a formatter. Of special interest to discrete scales are the `:Title`, `:lower`, and `:UPPER` formatters which lets you control the casing of strings. You can read more about these formatters in [the break formatting section of the `SCALE` documentation](../../clause/scale.qmd#break-formatting) +Besides direct renaming you can also provide a formatting string if you want the same to happen to all labels, e.g. add a prefix or suffix. The syntax for this is `LABEL * => '... {} ...'`. The current label will be inserted into the `{}` to produce the new label. Besides simply inserting the break value into the string, we can also provide a formatter. Of special interest to discrete scales are the `:Title`, `:lower`, and `:UPPER` formatters which lets you control the casing of strings. You can read more about these formatters in [the break formatting section of the `SCALE` documentation](../../clause/scale.qmd#break-formatting) You can combine formatting with direct renaming in which case the direct renaming has priority over the formatting. @@ -106,7 +106,7 @@ You can combine formatting with direct renaming in which case the direct renamin VISUALISE sex AS x FROM ggsql:penguins DRAW bar SCALE x - RENAMING 'null' => 'missing' + LABEL 'null' => 'missing' SCALE y FROM (0, null) ``` @@ -116,7 +116,7 @@ SCALE y FROM (0, null) VISUALISE species AS x FROM ggsql:penguins DRAW bar SCALE x - RENAMING * => 'Species: {}' + LABEL * => 'Species: {}' SCALE y FROM (0, null) ``` @@ -126,5 +126,5 @@ SCALE y FROM (0, null) VISUALISE bill_len AS x, bill_dep AS y, sex AS color FROM ggsql:penguins DRAW point SCALE color - RENAMING * => '{:Title}' + LABEL * => '{:Title}' ``` diff --git a/doc/syntax/scale/type/ordinal.qmd b/doc/syntax/scale/type/ordinal.qmd index 2440f5e11..8b7dc7daa 100644 --- a/doc/syntax/scale/type/ordinal.qmd +++ b/doc/syntax/scale/type/ordinal.qmd @@ -93,13 +93,13 @@ SCALE ORDINAL color ``` ## Renaming -Breaks are generally named by their value. However, you may wish to rename one, several, or all of these. The `RENAMING` clause allows you to do that both by directly renaming a specific break or by providing a formatting function. +Breaks are generally named by their value. However, you may wish to rename one, several, or all of these. The `LABEL` subclause allows you to do that both by directly renaming a specific break or by providing a formatting function. ### Direct renaming -When you provide a break value on the left and a break exists at that value then it will take on the label specified on the right. For example adding RENAMING 6 => 'June' will ensure that a month given as an integer gets the right name. +When you provide a break value on the left and a break exists at that value then it will take on the label specified on the right. For example adding LABEL 6 => 'June' will ensure that a month given as an integer gets the right name. ### Label formatting -Besides direct renaming you can also provide a formatting string if you want the same to happen to all labels, e.g. add a prefix or suffix. The syntax for this is `RENAMING * => '... {} ...'`. The current label will be inserted into the `{}` to produce the new label. Besides simply inserting the break value into the string, we can also provide a formatter. Of special interest to ordinal scales are the `:Title`, `:lower`, and `:UPPER` formatters which lets you control the casing of strings. You can read more about these formatters in [the break formatting section of the `SCALE` documentation](../../clause/scale.qmd#break-formatting) +Besides direct renaming you can also provide a formatting string if you want the same to happen to all labels, e.g. add a prefix or suffix. The syntax for this is `LABEL * => '... {} ...'`. The current label will be inserted into the `{}` to produce the new label. Besides simply inserting the break value into the string, we can also provide a formatter. Of special interest to ordinal scales are the `:Title`, `:lower`, and `:UPPER` formatters which lets you control the casing of strings. You can read more about these formatters in [the break formatting section of the `SCALE` documentation](../../clause/scale.qmd#break-formatting) You can combine formatting with direct renaming in which case the direct renaming has priority over the formatting. @@ -112,7 +112,7 @@ VISUALISE Ozone AS x, Temp AS y FROM ggsql:airquality DRAW point MAPPING Month AS color SCALE ORDINAL color - RENAMING 6 => 'June' + LABEL 6 => 'June' ``` #### Use string interpolation to add a suffix @@ -122,7 +122,7 @@ VISUALISE Ozone AS x, Temp AS y FROM ggsql:airquality DRAW point MAPPING Month AS color SCALE ORDINAL color - RENAMING * => '{}th month' + LABEL * => '{}th month' ``` #### Use a formatter to make labels shouty @@ -149,5 +149,5 @@ SCALE ORDINAL color 'Moderate Breeze', 'Fresh Breeze' ) - RENAMING * => '{:UPPER}' + LABEL * => '{:UPPER}' ``` diff --git a/doc/vendor/SKILL.md b/doc/vendor/SKILL.md index c7afd5d17..c62e9fdc2 100644 --- a/doc/vendor/SKILL.md +++ b/doc/vendor/SKILL.md @@ -20,7 +20,7 @@ Optional SQL part + required `VISUALISE`/`VISUALIZE` part. ```ggsql SELECT name, score_a, score_b FROM 'dataset.csv' WHERE value > 50 VISUALISE score_a AS x, score_b AS y - [DRAW / PLACE / SCALE / FACET / PROJECT / LABEL clauses] + [DRAW / PLACE / SCALE / FACET / PROJECT / TITLE clauses] ``` - **VISUALISE FROM**: VISUALISE supplies its own source (table/file/CTE/built-in), no trailing SELECT. ```ggsql @@ -99,7 +99,7 @@ Maps data β†’ aesthetic output; sensible defaults always apply. Only `aesthetic` ``` SCALE FROM TO VIA SETTING => , ... - RENAMING =>