AlgebraOfGraphics.jl icon indicating copy to clipboard operation
AlgebraOfGraphics.jl copied to clipboard

Add `highlight` transformation

Open jkrumbiegel opened this issue 1 year ago • 0 comments

The highlight transformation has a similar effect as the gghighlight extension from the ggplot ecosystem.

You can pass predicates which are then evaluated on the subgroups created by the given grouping variables in mapping. For example, this plot highlights all series with standard deviation of positional arg 2 (the y data) over some threshold:

using Statistics
using Random

Random.seed!(5)

nx = 100
ngroup = 8
df = (;
    x = repeat(1:nx, ngroup),
    y = reduce(vcat, [randn(nx) .* rand(range(0.01, 0.3, length = 20)) .+ i for i in 1:ngroup]),
    group = repeat(Char.(Int('A') .+ (0:ngroup-1)), inner = nx)
)
fg = data(df) *
    mapping(:x, :y, color = :group, layout = :group => x -> x > 'D' ? "Upper" : "Lower") *
    visual(Lines) *
    highlight(2 => y -> std(y) > 0.2) |> draw
image

You can also repeat the data split over facets in each facet. Whatever transformation has been done previously on that data in the facetted context will remain (so for example the histogram binning when using histogram()):

data((; x = randn(900) .+ repeat(0:3:6, inner = 300), group = repeat('A':'C', inner = 300))) *
    mapping(:x, color = :group, col = :group) *
    histogram(bins = 30) *
    highlight(:color => Returns(true), repeat_facets = true) |> draw
image

jkrumbiegel avatar Sep 05 '24 08:09 jkrumbiegel