Visual

AlgebraOfGraphics.visualFunction
visual(plottype; attributes...)

Create a Layer that will cause a plot spec multiplied with it to be visualized with plot type plottype, together with optional attributes.

The available plotting functions are documented here. Refer to plotting functions using upper CamelCase for visual's first argument (e.g. visual(Scatter), visual(BarPlot)). See the documentation of each plotting function to discover the available attributes. These attributes can be passed as additional keyword arguments to visual, or as part of the mapping you define.

The visual function can in principle be used for any plotting function that is defined using the @recipe macro from Makie. AlgebraOfGraphics just needs method definitions for aesthetic_mapping, which define what arguments of the plotting function map to which visual aesthetics. And for legend support, legend_elements must be overloaded for custom recipes as well, as Makie's default legend mechanism relies on instantiated plot objects, while AlgebraOfGraphics must go by the type and attributes alone.

Depending on its aesthetic_mapping, a plot type and its attributes may change certain semantics of a given data(...) * mapping(...) spec. For example, visual(BarPlot) will show mapping 1 on the x axis and 2 on the y axis, while visual(BarPlot, direction = :x) shows mapping 1 on y and 2 on x.

source
# Examples

using AlgebraOfGraphics, CairoMakie
set_aog_theme!()

df = (x=randn(1000), y=randn(1000))
plt = data(df) * mapping(:x, :y) * AlgebraOfGraphics.density(npoints=50)
draw(plt * visual(Heatmap)) # plot as heatmap (the default)

From AlgebraOfGraphics version 0.7 on, some attributes of the underlying Makie functions will not have an effect if they are controlled by scales instead. For example, continuous colors are completely controlled by color scales, so setting colormap in visual does not have an effect.

Set the colormap in the Scale options instead.

draw(plt, scales(Color = (; colormap = :viridis))) # set a different colormap
draw(plt * visual(Contour)) # plot as contour
draw(plt * visual(Contour, linewidth=2)) # plot as contour with thicker lines

This page was generated using Literate.jl.