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

Add highlight transformation #551

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Add highlight transformation #551

wants to merge 1 commit into from

Conversation

jkrumbiegel
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant