Functions
Drawing functions
AlgebraOfGraphics.draw
โ Functiondraw(s; axis=NamedTuple(), figure=NamedTuple, palettes=NamedTuple())
Draw a AlgebraOfGraphics.Layer
or AlgebraOfGraphics.Layers
object s
. The output can be customized by giving axis attributes to axis
, figure attributes to figure
, or custom palettes to palettes
. Legend and colorbar are drawn automatically. For finer control, use draw!
, legend!
, and colorbar!
independently.
draw(p::PaginatedLayers; kws...)
Draw each element of PaginatedLayers
p
and return a Vector{FigureGrid}
. Keywords kws
are passed to the underlying draw
calls.
draw(p::PaginatedLayers, i::Int; kws...)
Draw the ith element of PaginatedLayers
p
and return a FigureGrid
. Keywords kws
are passed to the underlying draw
call.
You can retrieve the number of elements using length(p)
.
AlgebraOfGraphics.draw!
โ Functiondraw!(fig, s; axis=NamedTuple(), palettes=NamedTuple())
Draw a AlgebraOfGraphics.Layer
or AlgebraOfGraphics.Layers
object s
on fig
. fig
can be a figure, a position in a layout, or an axis if s
has no facet specification. The output can be customized by giving axis attributes to axis
or custom palettes to palettes
.
AlgebraOfGraphics.colorbar!
โ Functioncolorbar!(figpos, grid; kwargs...)
Compute colorbar for grid
(which should be the output of draw!
) and draw it in position figpos
. Attributes allowed in kwargs
are the same as MakieLayout.Colorbar
.
AlgebraOfGraphics.legend!
โ Functionlegend!(figpos, grid; kwargs...)
Compute legend for grid
(which should be the output of draw!
) and draw it in position figpos
. Attributes allowed in kwargs
are the same as MakieLayout.Legend
.
AlgebraOfGraphics.paginate
โ Functionpaginate(l; layout=nothing, row=nothing, col=nothing)
Paginate l
, the Layer
or Layers
object created by an AlgebraOfGraphics
spec, to create a PaginatedLayers
object. This contains a vector of layers where each layer operates on a subset of the input data.
The PaginatedLayers
object can be passed to draw
which will return a Vector{FigureGrid}
rather than a single figure.
The keywords that limit the number of subplots on each page are the same that are used to specify facets in mapping
:
layout
: Maximum number of subplots in a wrapped linear layout.row
: Maximum number of rows in a 2D layout.col
: Maximum number of columns in a 2D layout.
Example
d = data((
x = rand(1000),
y = rand(1000),
group1 = rand(string.('a':'i'), 1000),
group2 = rand(string.('j':'r'), 1000),
))
layer_1 = d * mapping(:x, :y, layout = :group1) * visual(Scatter)
paginated_1 = paginate(layer_1, layout = 9)
figuregrids = draw(paginated_1)
layer_2 = d * mapping(:x, :y, row = :group1, col = :group2) * visual(Scatter)
paginated_2 = paginate(layer_2, row = 4, col = 3)
figuregrid = draw(paginated_2, 1) # draw only the first grid
Mapping helpers
AlgebraOfGraphics.renamer
โ Functionrenamer(arr::Union{AbstractArray, Tuple})
Utility to rename a categorical variable, as in renamer([value1 => label1, value2 => label2])
. The keys of all pairs should be all the unique values of the categorical variable and the values should be the corresponding labels. The order of arr
is respected in the legend.
Examples
julia> r = renamer(["class 1" => "Class One", "class 2" => "Class Two"])
AlgebraOfGraphics.Renamer{Vector{String}, Vector{String}}(["class 1", "class 2"], ["Class One", "Class Two"])
julia> println(r("class 1"))
Class One
Alternatively, a sequence of pair arguments may be passed.
julia> r = renamer("class 1" => "Class One", "class 2" => "Class Two")
AlgebraOfGraphics.Renamer{Tuple{String, String}, Tuple{String, String}}(("class 1", "class 2"), ("Class One", "Class Two"))
julia> println(r("class 1"))
Class One
If arr
does not contain Pair
s, elements of arr
are assumed to be labels, and the unique values of the categorical variable are taken to be the indices of the array. This is particularly useful for dims
mappings.
Examples
julia> r = renamer(["Class One", "Class Two"])
AlgebraOfGraphics.Renamer{Nothing, Vector{String}}(nothing, ["Class One", "Class Two"])
julia> println(r(2))
Class Two
AlgebraOfGraphics.sorter
โ Functionsorter(ks)
Utility to reorder a categorical variable, as in sorter(["low", "medium", "high"])
. A vararg method sorter("low", "medium", "high")
is also supported. ks
should include all the unique values of the categorical variable. The order of ks
is respected in the legend.
AlgebraOfGraphics.nonnumeric
โ Functionnonnumeric(x)
Transform x
into a non numeric type that is printed and sorted in the same way.
AlgebraOfGraphics.verbatim
โ Functionverbatim(x)
Signal that x
should not be rescaled, but used in the plot as is.
Theming
AlgebraOfGraphics.set_aog_theme!
โ Functionset_aog_theme!(; kwargs...)
Set the current theme to a predefined and opinionated theme, as defined by the unexported internal function AlgebraOfGraphics.aog_theme
.
To tweak the predefined theme, use the function Makie.update_theme!
. See the example below on how to change, e.g., default fontsize, title, and markersize.
For more information about setting themes, see the Theming
section of the Makie.jl
docs.
Examples
julia> using CairoMakie, AlgebraOfGraphics
julia> set_aog_theme!() # Sets a prefedined theme
julia> update_theme!( # Tweaks the current theme
fontsize=30,
markersize=40,
Axis=(title="MyDefaultTitle",)
)
AlgebraOfGraphics.aog_theme
โ Functionaog_theme(; fonts=[firasans("Medium"), firasans("Light")])
Return a NamedTuple
of theme settings. Intended for internal use. The provided functionality is exposed to the user by the function set_aog_theme!
.
Ticks helpers
AlgebraOfGraphics.datetimeticks
โ Functiondatetimeticks(datetimes::AbstractVector{<:TimeType}, labels::AbstractVector{<:AbstractString})
Generate ticks matching datetimes
to the corresponding labels
. The result can be passed to xticks
, yticks
, or zticks
.
datetimeticks(f, datetimes::AbstractVector{<:TimeType})
Compute ticks for the given datetimes
using a formatting function f
. The result can be passed to xticks
, yticks
, or zticks
.
Internal functions
AlgebraOfGraphics.scientific_eltype
โ Functionscientific_eltype(v)
Determine whether v
should be treated as a continuous, geometrical, or categorical array.
AlgebraOfGraphics.scientific_type
โ Functionscientific_type(T::Type)
Determine whether T
represents a continuous, geometrical, or categorical variable.
AlgebraOfGraphics.plottypes_attributes
โ Functionplottypes_attributes(entries)
Return plottypes and relative attributes, as two vectors of the same length, for the given entries
.
AlgebraOfGraphics.compute_attributes
โ Functioncompute_attributes(pl::ProcessedLayer, categoricalscales, continuousscales_grid, continuousscales)
Process attributes of a ProcessedLayer
. In particular,
- remove AlgebraOfGraphics-specific layout attributes,
- opt out of Makie cycling mechanism,
- customize behavior of
color
(implementingalpha
transparency), - customize behavior of bar
width
(default to one unit when not specified), - set correct
colorrange
.
Return computed attributes.