Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit aesthetics / scales #505

Merged
merged 178 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
d4f08e1
introduce `positional_mapping` field in `ProcessedLayer` and populate…
jkrumbiegel May 10, 2024
1487341
fix dictionary specification
jkrumbiegel May 10, 2024
d555e31
remap positional args where necessary
jkrumbiegel May 10, 2024
835d447
add violin
jkrumbiegel May 10, 2024
759a2ad
add fallback and HLines
jkrumbiegel May 10, 2024
c07b4ca
also remap labels
jkrumbiegel May 10, 2024
7a471d3
remove positional mapping again
jkrumbiegel May 27, 2024
0f06183
use VisualScale types as keys for scales
jkrumbiegel May 27, 2024
f9af04d
use visual scales when determining axis labels
jkrumbiegel May 27, 2024
e31af7f
first ColorScale
jkrumbiegel May 27, 2024
d1a95eb
fix continuous colorbar
jkrumbiegel May 27, 2024
be7dec7
determine legendable scales via types
jkrumbiegel May 27, 2024
e30547e
fix layout facetting
jkrumbiegel May 27, 2024
48b890a
refactor barplot and violin visual mappings
jkrumbiegel May 27, 2024
bf14743
rename VisualScale to Aesthetic to not conflict with cat/cont scales
jkrumbiegel May 27, 2024
d8f3cac
refactor dict type into const
jkrumbiegel May 27, 2024
e713eb4
refactor into MultiAesScaleDict to prepare multiple Aes of same type
jkrumbiegel May 27, 2024
8f3f2ea
add scale_mapping to ProcessedLayer and ScaleID to dissociate
jkrumbiegel May 28, 2024
be83bdb
add scatter mapping
jkrumbiegel May 28, 2024
b50b94b
introduce new legend approach requiring ProcessedLayers in AxisEntries
jkrumbiegel May 29, 2024
c09184b
fix colorbar again
jkrumbiegel May 29, 2024
b82ef96
fix wrapped layout
jkrumbiegel May 29, 2024
662eee9
fix violin legend
jkrumbiegel May 29, 2024
c016b64
remove shows
jkrumbiegel May 29, 2024
fa868ee
remove display
jkrumbiegel May 29, 2024
c55e1b7
fix row/col layout
jkrumbiegel May 29, 2024
79413bb
add scatter marker support back
jkrumbiegel May 30, 2024
4296e9c
introduce a way to style separate scales
jkrumbiegel May 30, 2024
15dc3ad
allow specifying scale properties just by symbol
jkrumbiegel May 30, 2024
41c0efa
use symbols to specify default and named scales
jkrumbiegel May 30, 2024
2d41590
refactor aesthetic_mapping logic to use nested dicts instead with def…
jkrumbiegel May 31, 2024
f47a4b9
fix legend having too many passes of processedlayers
jkrumbiegel May 31, 2024
962aeba
use plot attributes, not theme
jkrumbiegel May 31, 2024
993c4dd
add rainclouds
jkrumbiegel May 31, 2024
f57390b
fix group aes
jkrumbiegel May 31, 2024
52f9785
fix bug with positionals in legend
jkrumbiegel Jun 3, 2024
2a7b69f
add heatmap mapping and legend
jkrumbiegel Jun 3, 2024
3d9b25b
fix facetting scale and label logic
jkrumbiegel Jun 4, 2024
28aad12
incorporate continuous scale properties
jkrumbiegel Jun 4, 2024
920dea6
put props into scales to have them accessible
jkrumbiegel Jun 4, 2024
dc79531
route scale props differently
jkrumbiegel Jun 4, 2024
288516b
fix `linear`
jkrumbiegel Jun 5, 2024
26bd3f1
fix basic histogram
jkrumbiegel Jun 5, 2024
3a6eeb1
enable dodge and stack
jkrumbiegel Jun 5, 2024
24da649
fix reduction of colorbars and add lowclip/highclip
jkrumbiegel Jun 5, 2024
c018285
fix lowclip/highclip colors
jkrumbiegel Jun 5, 2024
4005880
fix bug in select
jkrumbiegel Jun 5, 2024
90a852a
fix linesfill legend
jkrumbiegel Jun 5, 2024
bb3c938
fix frequency
jkrumbiegel Jun 5, 2024
aabc813
fix expectation as well
jkrumbiegel Jun 5, 2024
819880d
move addition of mandatory attributes to processing step
jkrumbiegel Jun 5, 2024
461092b
fix wide data
jkrumbiegel Jun 5, 2024
1ac4c94
use extensible keyword definition via Val
jkrumbiegel Jun 5, 2024
ac84a60
use colormap from theme if available
jkrumbiegel Jun 5, 2024
a463e50
use only colormap from scale
jkrumbiegel Jun 6, 2024
ff6599d
error if unused scales get scale props
jkrumbiegel Jun 6, 2024
2c5344e
add rangebars and errorbars
jkrumbiegel Jun 6, 2024
5a0a8d2
fix legend for errorbars/rangebars
jkrumbiegel Jun 6, 2024
71bab7a
fix rangebar/errorbar direction
jkrumbiegel Jun 6, 2024
9021a57
allow overriding labels for each scale
jkrumbiegel Jun 6, 2024
bc22424
fix bug when palette option is not present
jkrumbiegel Jun 6, 2024
48fa4b6
implement category overrides
jkrumbiegel Jun 7, 2024
3db349b
allow overriding categorical scale numbers via palette
jkrumbiegel Jun 7, 2024
f1147d8
capitalize scale keys
jkrumbiegel Jun 10, 2024
7082ad0
add type scale props for better validation
jkrumbiegel Jun 10, 2024
6562f81
allow disabling legend for categorical scales
jkrumbiegel Jun 10, 2024
b192e08
simplify empty categorical props and add palette
jkrumbiegel Jun 10, 2024
fbc06ff
add continuous scale props scaffolding
jkrumbiegel Jun 10, 2024
7801b40
add continuous markersize
jkrumbiegel Jun 10, 2024
ded376c
allow categorical markersize too
jkrumbiegel Jun 10, 2024
a431b43
fix definition check logic
jkrumbiegel Jun 10, 2024
a0f8bad
add markersize legend
jkrumbiegel Jun 10, 2024
15b6657
fix weird merging bug
jkrumbiegel Jun 10, 2024
da3c9af
try handling nonexisting plot type case
jkrumbiegel Jun 10, 2024
7fed437
fix undefvarerror
jkrumbiegel Jun 10, 2024
ed7feb6
delete test that doesn't make sense anymore
jkrumbiegel Jun 10, 2024
2e59561
fix tests
jkrumbiegel Jun 10, 2024
03bcd54
add linestyle to fix precompile
jkrumbiegel Jun 10, 2024
012104b
try fixing stackoverflow on 1.6
jkrumbiegel Jun 11, 2024
39a9413
handle verbatim missing scales
jkrumbiegel Jun 11, 2024
5a13975
enable `Text` usage
jkrumbiegel Jun 11, 2024
f1818f1
enable boxplot
jkrumbiegel Jun 11, 2024
0a0e9cb
enable violin side
jkrumbiegel Jun 11, 2024
c93a6fc
enable basic contour plots
jkrumbiegel Jun 12, 2024
ca8e095
fix docs examples
jkrumbiegel Jun 12, 2024
f392213
fix facetting example
jkrumbiegel Jun 12, 2024
9036051
fix example
jkrumbiegel Jun 12, 2024
fc389e7
fix cover image variable
jkrumbiegel Jun 12, 2024
7f27a1f
fix choropleth example
jkrumbiegel Jun 12, 2024
ea2525e
fix poly example
jkrumbiegel Jun 12, 2024
923660c
fix 3 arg lines/scatter
jkrumbiegel Jun 12, 2024
edc0980
add visual for surface
jkrumbiegel Jun 12, 2024
270563a
fix wireframe
jkrumbiegel Jun 12, 2024
080d0c3
remove internals section (at least for now)
jkrumbiegel Jun 12, 2024
8535d07
fix problem with sentinelarrays being passed through
jkrumbiegel Jun 17, 2024
da15185
enable band
jkrumbiegel Jun 17, 2024
cc54736
add ability to reorder/regroup legend
jkrumbiegel Jun 18, 2024
f0ef75c
allow any label for facets
jkrumbiegel Jun 18, 2024
496415a
allow arbitrary transforms on categories
jkrumbiegel Jun 18, 2024
5e99b70
allow function over categories as palette
jkrumbiegel Jun 18, 2024
4939eda
merge dodged barplots as well
jkrumbiegel Jun 18, 2024
25155ab
fix test
jkrumbiegel Jun 18, 2024
0988cb4
using datavalues in tests
jkrumbiegel Jun 18, 2024
590804a
fix cat scale merging
jkrumbiegel Jun 18, 2024
479dde3
simplify palette logic, always pass through vectors
jkrumbiegel Jun 19, 2024
a87347b
remove empty titles completely in legend
jkrumbiegel Jun 19, 2024
99c22de
remove palette from categorical scale
jkrumbiegel Jun 19, 2024
2746079
fix legend merging
jkrumbiegel Jun 19, 2024
12b574e
add scale docs
jkrumbiegel Jun 19, 2024
caa13fc
docs for `categories`
jkrumbiegel Jun 19, 2024
2d20a5e
fix now incorrect docs
jkrumbiegel Jun 19, 2024
8af750d
fix docs problems
jkrumbiegel Jun 19, 2024
1f546d7
add X & Y and Layout examples
jkrumbiegel Jun 20, 2024
234705c
add legend order examples
jkrumbiegel Jun 20, 2024
15104a7
add contours transformation
jkrumbiegel Jun 24, 2024
355290a
add filled_contours analysis
jkrumbiegel Jun 25, 2024
b9de3a1
contour's'
jkrumbiegel Jun 25, 2024
cb8c39a
fix legend problem
jkrumbiegel Jun 25, 2024
6896b9a
add convenience `draw` for `|>`
jkrumbiegel Jun 25, 2024
8d6c541
remove docstring so documenter doesn't complain
jkrumbiegel Jun 25, 2024
d360e7c
add helpful error when old keyword `palette` is used
jkrumbiegel Jun 26, 2024
fb92cd9
add docs for `contours` and `filled_contours`
jkrumbiegel Jun 26, 2024
5b14f88
can't use multiline backslash style in 1.6
jkrumbiegel Jun 26, 2024
405ade7
use Dictionary{Symbol,Any} in more places to avoid NamedTuple compile
jkrumbiegel Jun 26, 2024
6e6a7e1
fix test
jkrumbiegel Jun 26, 2024
1d5c615
pairs on kwargs
jkrumbiegel Jun 26, 2024
e499ee0
fix untyped scales vector
jkrumbiegel Jun 26, 2024
8ac0d76
fix draw!
jkrumbiegel Jun 26, 2024
89ce7d5
fix more dict kwargs
jkrumbiegel Jun 26, 2024
423b86a
one more pairs
jkrumbiegel Jun 26, 2024
b00c3fb
enable ablines
jkrumbiegel Jun 26, 2024
25e9a3e
add scatterlines
jkrumbiegel Jun 26, 2024
4a5b5d8
add basic aesthetics tests
jkrumbiegel Jun 27, 2024
7586b91
add legend tests
jkrumbiegel Jun 27, 2024
6615100
more tests of scale properties
jkrumbiegel Jun 27, 2024
9c57a0f
add examples for discrete scale transformations
jkrumbiegel Jun 27, 2024
2b377b6
add secondary scales example
jkrumbiegel Jun 27, 2024
1d98b56
add example for merged legend
jkrumbiegel Jun 27, 2024
d807ce8
tests for scale errors
jkrumbiegel Jun 27, 2024
8f25010
type aesthetic mappings with scientific types
jkrumbiegel Jun 27, 2024
a818c61
type aesthetic mappings with scientific types
jkrumbiegel Jun 27, 2024
de3e8fa
fix kw method error check for earlier julia versions
jkrumbiegel Jun 27, 2024
a9257a3
add hspan and vspan
jkrumbiegel Jun 29, 2024
80a42e1
add four-arg errorbars
jkrumbiegel Jun 29, 2024
010a689
replace `scales` keyword with `scales` function as positional arg
jkrumbiegel Jul 15, 2024
9bcd08b
fix longpoly ambiguity
jkrumbiegel Jul 15, 2024
e031d50
fix docs
jkrumbiegel Jul 15, 2024
d60126c
fix docstrings
jkrumbiegel Jul 15, 2024
bc8e96a
fix tests
jkrumbiegel Jul 15, 2024
07916e6
fix remaining keyword scales
jkrumbiegel Jul 15, 2024
fb30072
move aesthetics to their own file
jkrumbiegel Jul 15, 2024
879671d
fix test
jkrumbiegel Jul 15, 2024
25f83e5
bring back default arg to fix test
jkrumbiegel Jul 15, 2024
7f39b63
add docstrings to `scale` and `scales`
jkrumbiegel Jul 15, 2024
1884e9b
add docstrings explicitly
jkrumbiegel Jul 15, 2024
3a319ca
add `pregrouped`, `direct` and mapping docs & tests
jkrumbiegel Jul 15, 2024
e2f4c78
fix pregrouped example from gallery
jkrumbiegel Jul 15, 2024
4a2b691
fix ambiguity
jkrumbiegel Jul 15, 2024
3da6106
revert heading
jkrumbiegel Jul 15, 2024
e85d192
add docstring for `data` and move things around a bit
jkrumbiegel Jul 15, 2024
244a0ee
add `visual` docstring
jkrumbiegel Jul 15, 2024
5e1422f
add mapping without data example
jkrumbiegel Jul 16, 2024
144c04b
fix scalar-only mapping without data
jkrumbiegel Jul 16, 2024
5c64e35
add quotes to fix yaml parsing
jkrumbiegel Jul 16, 2024
0f03329
still problems with title format, try without backticks
jkrumbiegel Jul 16, 2024
8ea51a3
add reference tests
jkrumbiegel Jul 16, 2024
5b1d591
add more reference tests
jkrumbiegel Jul 16, 2024
3967d55
qqplot test
jkrumbiegel Jul 16, 2024
65c846c
add DelimitedFiles to test deps
jkrumbiegel Jul 16, 2024
9eb6051
arrows reftest
jkrumbiegel Jul 16, 2024
1b85be0
avoid double CI runs on push to PR
jkrumbiegel Jul 16, 2024
b45f387
cancel in progress
jkrumbiegel Jul 16, 2024
93fe05c
remove allequal for 1.6 compat
jkrumbiegel Jul 16, 2024
5be3528
expectation ref image
jkrumbiegel Jul 16, 2024
f18feb2
remove dead code
jkrumbiegel Jul 16, 2024
a79a61b
Add release notes
jkrumbiegel Jul 16, 2024
ab2d500
copy NEWS.md to docs
jkrumbiegel Jul 16, 2024
3f79402
fix path
jkrumbiegel Jul 16, 2024
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
15 changes: 13 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
name: CI
on:
- push
- pull_request
pull_request:
branches:
- master
push:
tags:
- '*'
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
Expand Down
46 changes: 37 additions & 9 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,64 @@
# AlgebraOfGraphics.jl v0.6 Release Notes
# Release Notes

## Breaking Changes
## v0.7

### Breaking Changes

- The `palette` keyword of `draw` linking palettes to keyword arguments was removed. Instead, palettes need to be passed to specific scales like `draw(..., scales(Color = (; palette = :Set1_3)))`
- All recipes need to have the new function `aesthetic_mapping` defined for all sets of positional arguments that should be supported, as can be seen in `src/aesthetics.jl`. This breaks usage of all custom recipes. Additionally, not all Makie plots have been ported to the new system yet. If you encounter missing plots, or missing attributes of already ported plots, please open an issue.
- All custom recipes that should be displayed in a legend, need to have `legend_elements(P, attributes, scale_args)` defined as can be seen in `src/guides/legend.jl`. AlgebraOfGraphics cannot use the same default mechanism as Makie, which can create a legend from an existing plot, because AlgebraOfGraphics needs to create the legend before the plot is instantiated.
- Pregrouped data cannot be passed anymore to the plain `mapping(...)` without any `data(tabular)`. Instead, you should use `pregrouped(...)` which is a shortcut for `data(Pregrouped()) * mapping(...)`.
- `Contour` and `Contourf` generally do not work anymore with `visual()`. Instead, the `contours()` and `filled_contours()` analyses should be used. `Contour` can still be used with categorical colors, but not with continuous ones.
- All colormap properties for continuous color scales need to be passed via `scales` now, and not through `visual`. This is to have central control over the scale as it can be used by multiple `visual`s simultaneously.

### New Features

- Horizontal barplots, violins, errorbars, rangebars and other plot types that have two different orientations work correctly now. Axis labels switch accordingly when the orientation is changed.
- Plotting functions whose positional arguments don't correspond to X, Y, Z work correctly now. For example, `HLines` (1 => Y) or `rangebars` (1 => X, 2 => Y, 3 => Y).
- It is possible to add categories beyond those present in the data with the `categories` keyword within a scale's settings. It is also possible to reorder or otherwise transform the existing categories by passing a function to `categories`.
- The supported attributes are not limited anymore to a specific set of names, for example, `strokecolor` can work the same as `color` did before, and the two can share a scale via their shared aesthetic type.
- There can be multiple scales of the same aesthetic now. This allows to have separate legends for different plot types using the same aesthetics. Scale separation works by pairing a variable in `mapping` with a `scale(id_symbol)`.
- Legend entries can be reordered using the `legend = (; order = ...)` option in `draw`. Specific scales can opt out of the legend by passing `legend = false` in `scales`.
- Labels can now be anything that Makie supports, primarily `String`s, `LaTeXString`s or `rich` text.
- Legend elements now usually reflect all attributes set in their corresponding `visual`.
- Simple column vectors of data can now be passed directly to `mapping` without using `data` first. Additionally, scalar values are accepted as a shortcut for columns with the same repeated value.
- Columns from outside a table source in `data` can now be passed to `mapping` by wrapping them in the `direct` function. Scalar values are accepted as a shortcut for columns with the same repeated value. For example, to create a label for columns `x` and `y` from a dataframe passed to `data`, one could now do `mapping(:x, :y, color = direct("label"))` without having to create a column full of `"label"` strings first.
- The numbers at which categorical values are plotted on x and y axis can now be changed via `scales(X = (; palette = [1, 2, 4]))` or similar.
- Continuous marker size scales can now be shown in the legend. Numerical values are proportional to area and not diameter now, which makes more sense with respect to human perception. The min and max marker size can be set using the `sizerange` property for the respective scale in `scales`.

## v0.6

### Breaking Changes

- Default axis linking behavior has changed: now only axes corresponding to the same variable are linked. For consistency with `row`/`col`, `layout` will hide decorations of linked axes and span axis labels if appropriate.

## New Features
### New Features

- Customizable axis linking behavior.
- Customizable legend and colorbar position and look.
- In v0.6.1, support `level` in `linear` analysis for confidence interval.
- In v0.6.8, added `choropleth` recipe to supersede `geodata` for geographical data.
- In v0.6.11, added `paginate` for pagination of large facet plots.

## Internal changes
### Internal changes

- In v0.6.1, replaced tuples and named tuples in `Layer` and `Entry` with dictionaries from [Dictionaries.jl](https://github.com/andyferris/Dictionaries.jl).
- In v0.6.1, split internal `Entry` type into `ProcessedLayer` (to be used for analyses) and `Entry` (to be used for plotting).

# AlgebraOfGraphics.jl v0.5 Release Notes
## v0.5

## Breaking Changes
### Breaking Changes

- `Axis(ae)` has been replaced by `ae.axis`.
- `Legend(fg)` has been replaced by `legend!(fg)` and `colorbar!(fg)`.

## New Features
### New Features

- `legend!` and `colorbar!` API allows for custom legend placement.

# AlgebraOfGraphics.jl v0.4 Release Notes
## v0.4

## Breaking Changes
### Breaking Changes

- Removed deprecations for `style` and `spec` (now only `mapping` and `visual` are allowed).
- Analyses now require parentheses (i.e. `linear()` instead of `linear`).
Expand Down
7 changes: 6 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ GLM = "38e38edf-8417-5370-95a0-9cbb8c7f171a"
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
GridLayoutBase = "3955a311-db13-416c-9275-1d80ed98e5e9"
Isoband = "f1662d9f-8043-43de-a69a-05efc1cc6ff4"
KernelDensity = "5ab0869b-81aa-558d-bb23-cbf5423bbe9b"
Loess = "4345ca2d-374a-55d4-8d30-97f9976e7612"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
PlotUtils = "995b91a9-d308-5afd-9ec6-746e21dbc043"
PolygonOps = "647866c9-e3ac-4575-94e7-e3d426903924"
PooledArrays = "2dfb63ee-cc39-5dd5-95bd-886bf059d720"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
RelocatableFolders = "05181044-ff0b-4ac5-8273-598c1e38db00"
Expand Down Expand Up @@ -44,10 +46,13 @@ Tables = "1.4"
julia = "1.6"

[extras]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
ImageInTerminal = "d8c32880-2388-543b-8c61-d9f865259254"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Shapefile = "8e980c4a-a4fe-5da2-b3a7-4b4b0353a2f4"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Random", "Shapefile", "Statistics", "Test"]
test = ["Random", "Shapefile", "Statistics", "Test", "CairoMakie", "DelimitedFiles", "ImageInTerminal"]
29 changes: 29 additions & 0 deletions docs/gallery/gallery/data manipulations/no_data.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# ---
# title: "Using mapping without tabular data"
# cover: assets/no_data.png
# description: "Passing columnar data directly to `mapping`."
# author: "[Julius Krumbiegel](https://github.com/jkrumbiegel)"
# ---

# Sometimes it's easier to specify columnar data directly within `mapping`
# rather than first storing it in some tabular `data` source and accessing it by
# column name. Note that you can also use scalar values which will be treated
# like columns with repeated elements. In the example below, we specify `color = "marker"`
# instead of the more verbose `color = fill("marker", 3)`.

using AlgebraOfGraphics, CairoMakie
set_aog_theme!() #src

x = 1:100
y = sin.(range(0, 2pi, length = 100))

plt = mapping(x, y, color = repeat(["high", "low"], inner = 50)) *
visual(Lines) +
mapping([20, 28, 51], color = "marker" => scale(:secondary)) *
visual(VLines, linestyle = :dash)

fg = draw(plt, scales(secondary = (; palette = [:gray80])))

# save cover image #src
mkpath("assets") #src
save("assets/no_data.png", fg) #src
14 changes: 7 additions & 7 deletions docs/gallery/gallery/data manipulations/pre_grouped_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ using AlgebraOfGraphics, CairoMakie
set_aog_theme!() #src


x = [rand(10) for i in 1:3]
y = [rand(10) for i in 1:3]
z = [rand(10) for i in 1:3]
x = [rand(10) .+ i for i in 1:3]
y = [rand(10) .+ i for i in 1:3]
z = [rand(10) .+ i for i in 1:3]
c = ["a", "b", "c"]

m = mapping(x, y, color=c => (t -> "Type " * t ) => "Category")
m = pregrouped(x, y, color=c => (t -> "Type " * t ) => "Category")
draw(m)

#

m = mapping(x, (y, z) => (+) => "sum", color=c => (t -> "Type " * t ) => "Category")
m = pregrouped(x, (y, z) => (+) => "sum", color=c => (t -> "Type " * t ) => "Category")
draw(m)

#

m = mapping(x, [y z], color=dims(1) => renamer(["a", "b", "c"]))
m = pregrouped(x, [y z], color=dims(1) => renamer(["a", "b", "c"])) * visual(Scatter)
draw(m)

#

m = mapping(x, [y z], color=["1" "2"])
m = pregrouped(x, [y z], color=["1" "2"])
layers = visual(Scatter) + linear()
fg = draw(m * layers)

Expand Down
2 changes: 1 addition & 1 deletion docs/gallery/gallery/layout/faceting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ draw(plt, facet=(; linkxaxes=:none, linkyaxes=:none))

# ## Facet wrap with specified layout for rows and cols

draw(plt, palettes=(layout=[(1, 1), (1, 2), (2, 1), (2, 2), (3, 1)],))
draw(plt, scales(Layout = (; palette = [(1, 1), (2, 1), (3, 1), (1, 2), (2, 2)])))

# ## Adding traces to only some subplots

Expand Down
2 changes: 1 addition & 1 deletion docs/gallery/gallery/scales/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"description": "Some advanced keywords to tweak the plot",
"order": ["discrete_scales.jl", "continuous_scales.jl", "custom_scales.jl", "multiple_color_scales.jl", "prescaled_data.jl", "legend_merging.jl"]
"order": ["discrete_scales.jl", "continuous_scales.jl", "custom_scales.jl", "secondary_scales.jl", "multiple_color_scales.jl", "prescaled_data.jl", "legend_merging.jl"]
}
16 changes: 8 additions & 8 deletions docs/gallery/gallery/scales/custom_scales.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ c=rand(Bool, length(x))
d=rand(Bool, length(x))
df = (; x, y, u, v, c, d)
colors = [colorant"#E24A33", colorant"#348ABD"]
heads = ['', '']
heads = ['', '']
plt = data(df) *
mapping(:x, :y, :u, :v) *
mapping(arrowhead=:c => nonnumeric) *
mapping(arrowcolor=:d => nonnumeric) *
visual(Arrows, arrowsize=10, lengthscale=0.3)
draw(plt; palettes=(arrowcolor=colors, arrowhead=heads))
mapping(arrowhead = :c => nonnumeric) *
mapping(color = :d => nonnumeric) *
visual(Arrows, arrowsize=10, lengthscale=0.4, linewidth = 1)
fg = draw(plt, scales(Marker = (; palette = heads), Color = (; palette = colors)))

# To associate specific attribute values to specific data values, use pairs.
# Missing keys will cycle over values that are not pairs.
Expand All @@ -50,8 +50,8 @@ y = rand(100)
z = rand(["a", "b", "c", "d"], 100)
df = (; x, y, z)
plt = data(df) * mapping(:x, :y, color=:z)
colors = ["a" => colorant"#E24A33", "c" => colorant"#348ABD", colorant"#988ED5", colorant"#777777"]
draw(plt; palettes=(color=colors,))
colors = ["a" => :tomato, "c" => :lime, colorant"#988ED5", colorant"#777777"]
draw(plt, scales(Color = (; palette = colors)))

# Categorical color gradients can also be passed to `palettes`.

Expand All @@ -61,7 +61,7 @@ z = rand(["a", "b", "c", "d", "e", "f", "g", "h"], 200)
df = (; x, y, z)
plt = data(df) * mapping(:x, :y, color=:z)
colors = cgrad(:cividis, 8, categorical=true)
fg = draw(plt; palettes=(color=colors,))
draw(plt, scales(Color = (; palette = colors)))

# save cover image #src
mkpath("assets") #src
Expand Down
70 changes: 67 additions & 3 deletions docs/gallery/gallery/scales/discrete_scales.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,48 @@ set_aog_theme!() #src

# By default categorical ticks, as well as names from legend entries, are taken from the
# value of the variable converted to a string. Scales can be equipped with labels to
# overwrite that
# overwrite that. You can either use the `renamer` function to apply relabeling or reordering to
# some column on the fly, or you use the `categories` keyword for the respective scale
# in the `draw` call.
#
# !!! note
# The `categories` keyword (added in v0.7) also allows adding categories not present in the data.

df = (x=rand(["a", "b", "c"], 100), y=rand(100))
plt = data(df) * mapping(:x, :y) * visual(BoxPlot)
draw(plt)

#

df = (x=rand(["a", "b", "c"], 100), y=rand(100))
plt = data(df) * mapping(:x, :y) * visual(BoxPlot)
draw(plt, scales(X = (;
categories = ["a" => "label1", "b" => "label2", "c" => "label3"]
)))

# The same operation can be done with `renamer` as well which modifies the input data

plt = data(df) *
mapping(
:x => renamer("a" => "label1", "b" => "label2", "c" => "label3"),
:y
) * visual(BoxPlot)
draw(plt)

# The order can also be changed by tweaking the scale
# With `categories`, you can add further categories that might be missing from your data

plt = data(df) * mapping(:x, :y) * visual(BoxPlot)
draw(plt, scales(X = (;
categories = ["a", "missing", "b", "c"]
)))

# The order can also be changed:

plt = data(df) * mapping(:x, :y) * visual(BoxPlot)
draw(plt, scales(X = (;
categories = ["b" => "label b", "a" => "label a", "c" => "label c"]
)))

# Or with `renamer`:

plt = data(df) *
mapping(
Expand All @@ -35,6 +60,45 @@ plt = data(df) *
) * visual(BoxPlot)
fg = draw(plt)

# When categories come from different datasets, you can either apply the same `renamer` to multiple mappings,
# or set the ordering at one place in `categories`:

df1 = (; x = rand(["one", "two"], 100), y = randn(100))
df2 = (; x = rand(["three", "four"], 50), y = randn(50))
plt = (data(df1) + data(df2)) * mapping(:x, :y) * visual(BoxPlot)
draw(plt)

#

draw(plt, scales(X = (;
categories = ["one", "two", "three", "four"]
)))

# You can also pass a function to `categories`, which has to return a vector with
# (optionally labelled) categories in the desired order.
# For example, strings are by default ordered alphabetically:

df = (; name = ["Anna Coolidge", "Berta Bauer", "Charlie Archer"], age = [34, 79, 58])
plt = data(df) * mapping(:name, :age) * visual(BarPlot)
draw(plt)

# Instead of specifying the order manually, we could use a function to order by last name:

draw(plt, scales(X = (;
categories = cats -> sort(cats; by = name -> split(name)[2])
)))

# Or even combine this with a relabeling function that shortens the first name to the initial:

function initialed(name)
a, b = split(name)
return name => "$(first(a)). $b"
end

draw(plt, scales(X = (;
categories = cats -> initialed.(sort(cats; by = name -> split(name)[2]))
)))

# save cover image #src
mkpath("assets") #src
save("assets/discrete_scales.png", fg) #src
3 changes: 1 addition & 2 deletions docs/gallery/gallery/scales/multiple_color_scales.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
using AlgebraOfGraphics, CairoMakie
set_aog_theme!() #src

# Normally, a unique scale is associated to each given attribute. Color is an important
# exception: continuous and discrete color scales can coexist in the same plot.
# Continuous and discrete color scales can coexist in the same plot.
# This should be used sparingly, as it can make the plot harder to interpret.

x = range(-π, π, length=100)
Expand Down
Loading
Loading