unfoldtoolbox / UnfoldMakie.jl

Plotting and visualization tools for EEG data, with additional Unfold.jl regression ERP methods. Based on the visualization libraries Makie.jl and AlgebraOfGraphics.jl
https://unfoldtoolbox.github.io/UnfoldMakie.jl/
MIT License
17 stars 7 forks source link

Allow AoG.sorter( ) #232

Closed ReneSkukies closed 1 month ago

ReneSkukies commented 2 months ago

In AoG I can use the sorter function in case variables won't get sorted in the way I want (e.g. into subplots or inside a plot). Here is an example:

using Unfold, AlgebraOfGraphics

sorting = ['S', 'R']

eff = effects(Dict(:duration => 75:20:300), m)

data(eff) * visual(Lines) * mapping(:yhat, col = :eventname => sorter(sorting), color = :duration, group = :duration => nonnumeric) |> draw()

This gives me the following plot: image

However, in UnfoldMakie the following does not work:

using Unfold, UnfoldMakie

sorting = ['S', 'R']

eff = effects(Dict(:duration => 75:20:300), m)

plot_erp(eff;
        mapping = (; col = :eventname => UnfoldMakie.AlgebraOfGraphics.sorter(sorting), color = :duration, group = :duration => nonnumeric)
    )

And without the sorting, the plot looks like this: image

Is it possible to include sorting in UM? Or is there already a way for this?

ReneSkukies commented 2 months ago

In case anyone runs into this problem: AoG (which is used for the plots by UnfoldMakie) seems to plot subplots in alphabetical order of the subplot name. Thus you can get around the issue by renaming the stimuli in your model.

For the example above, renaming stimuli to 'A' and 'R' would result in correctly plotted subplots.

vladdez commented 1 month ago

we maybe accidentially fixed this :shrug:

using Unfold, AlgebraOfGraphics

data,evts = UnfoldSim.predef_eeg()

evts
m = fit(UnfoldModel,["car"=>(@formula(0~1+continuous),firbasis((-0.1,1),100)),"face"=>(@formula(0~1+continuous),firbasis((-0.1,1),100))],evts,data;eventcolumn=:condition)  
eff = effects(Dict(:continuous => 75:20:300), m)
sorting = ["car","face"]

sorting = ["face","car"]

plot_erp(eff;
        mapping = (; col = :eventname => sorter(sorting), 
        color = :continuous,group=:continuous)
    )

works now

image

and

image

vladdez commented 1 month ago

fixed #237