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

complete rewrite of parallel plots #121

Merged
merged 16 commits into from
Nov 30, 2023
Merged
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.vscode/
/test/Manifest.toml
/docs/Manifest.toml

/docs/.CondaPkg
/Manifest.toml
/docs/build/
/docs/src/generated
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
GridLayoutBase = "3955a311-db13-416c-9275-1d80ed98e5e9"
ImageFiltering = "6a3955dd-da59-5b1f-98d4-e7296123deb5"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Expand Down
17 changes: 9 additions & 8 deletions docs/literate/plot_results_styling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,30 @@
using CairoMakie


include(joinpath(dirname(pathof(Unfold)), "../test/test_utilities.jl") ) # to load data
include(joinpath(dirname(pathof(Unfold)), "../test/test_utilities.jl")) # to load data
data, evts = loadtestdata("test_case_3b");
basisfunction = firbasis(τ=(-0.4,.8),sfreq=50,name="stimulus")
f = @formula 0~1+conditionA+continuousA
basisfunction = firbasis(τ = (-0.4, 0.8), sfreq = 50, name = "stimulus")
f = @formula 0 ~ 1 + conditionA + continuousA

bfDict = Dict(Any=>(f,basisfunction))
bfDict = Dict(Any => (f, basisfunction))

m = fit(UnfoldModel,bfDict,evts,data);
results = coeftable(m); nothing
m = fit(UnfoldModel, bfDict, evts, data);
results = coeftable(m);
nothing;

# # Styling your plot
# ## Mapping's
# everything you can put in a mapping(...) AoG group can be modified, for instance:
plot_results(results,linestyle=:coefname)
plot_results(results, mapping = (; linestyle = :coefname))

# ## Adding P-values
# You can provide a dataframe with columns (must): `:from`,`:to`,future versions might allow a `:pvalue` column
pvals = DataFrame( :from=>[0.1,0.,-0.1],

Check warning on line 29 in docs/literate/plot_results_styling.jl

View workflow job for this annotation

GitHub Actions / code-style

[JuliaFormatter] reported by reviewdog 🐶 Raw Output: docs/literate/plot_results_styling.jl:29:-pvals = DataFrame( :from=>[0.1,0.,-0.1], docs/literate/plot_results_styling.jl:30:- :to=>[0.5,0.3,0.6], docs/literate/plot_results_styling.jl:31:- :pvalue=>[0.01,0.01,0.001], # optional docs/literate/plot_results_styling.jl:32:- :coefname=>["(Intercept)","conditionA","continuousA"]) docs/literate/plot_results_styling.jl:29:+pvals = DataFrame( docs/literate/plot_results_styling.jl:30:+ :from => [0.1, 0.0, -0.1], docs/literate/plot_results_styling.jl:31:+ :to => [0.5, 0.3, 0.6], docs/literate/plot_results_styling.jl:32:+ :pvalue => [0.01, 0.01, 0.001], # optional docs/literate/plot_results_styling.jl:33:+ :coefname => ["(Intercept)", "conditionA", "continuousA"], docs/literate/plot_results_styling.jl:34:+)
:to=>[0.5,0.3,0.6],
:pvalue=>[0.01,0.01,0.001], # optional
:coefname=>["(Intercept)","conditionA","continuousA"])

plot_results(results,pvalue=pvals)
plot_results(results, pvalue = pvals)

# !!! note
# If you do not give the coefname, all lines will be the same color as the first color-grouping (typically coefname), and they might overlap!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
# If you do not give the coefname, all lines will be the same color as the first color-grouping (typically coefname), and they might overlap!
# If you do not give the coefname, all lines will be the same color as the first color-grouping (typically coefname), and they might overlap!

46 changes: 0 additions & 46 deletions docs/literate/reference/positions.md

This file was deleted.

5 changes: 3 additions & 2 deletions docs/literate/tutorials/erp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ plot_erp(
res_effects;
mapping = (; y = :yhat, color = :continuous, group = :continuous),
legend = (; nbanks = 2),
layout = (; showLegend = true, legend_position = :right),
categorical_color = false, categorical_group = true,
layout = (; show_legend = true, legend_position = :right),
categorical_color = false,
categorical_group = true,
)


Expand Down
3 changes: 1 addition & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ makedocs(;
],
"How To" => [
"Butterfly Colormap" => "how_to/position2color.md",
"Fix Parallel Coordinates Plot" => "how_to/fix_pcp.md",
"Hide Axis Spines and Decorations" => "how_to/hide_deco.md",
"Include multiple Visualizations in one Figure" => "how_to/mult_vis_in_fig.md",
"Show out of Bounds Label" => "how_to/show_oob_labels.md",
"Designmatrix: Show out of Bounds Label" => "how_to/show_oob_labels.md",
],
"Reference" => [
"Convert 3D positions / montages to 2D layouts" => "generated/reference/positions.md",
Expand Down
1 change: 1 addition & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ Internally, we use a `PlotConfig` struct to keep track of common plot options, i

```@docs
PlotConfig
UnfoldMakie.PCPTicks
```
33 changes: 0 additions & 33 deletions docs/src/how_to/fix_pcp.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/src/how_to/mult_vis_in_fig.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ plot_erp!(f[2, 4:5], res_effects; categorical_color=false, categorical_group=tru
legend=(; nbanks=2),
layout=(; show_legend=true, legend_position=:right))

plot_parallelcoordinates!(f[3, 2:3], uf_5chan, [1, 2, 3, 4, 5]; mapping=(; color=:coefname),
plot_parallelcoordinates(f[3, 2:3], uf_5chan; mapping=(; color=:coefname),
layout=(; legend_position=:bottom))

plot_erpimage!(f[1, 4:5], times, dat_e; sortvalues=evts.Δlatency)
Expand Down
130 changes: 109 additions & 21 deletions docs/src/tutorials/parallelcoordinates.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,130 @@ using DataFrames
using CairoMakie
```

## Data

We use the test data of `erpcore-N170.jld2`.

## Data generation
```@example main
include("../../example_data.jl")
results_plot, positions = example_data();
r1, positions = example_data();
r2 = deepcopy(r1)
r2.coefname .= "B" # create a second category
r2.estimate .+= rand(length(r2.estimate))*0.1
results_plot = vcat(r1, r2);
nothing #hide
```

## Plot PCPs

```@example main
plot_parallelcoordinates(results_plot, [5,3,2]; # this selects channel 5,3 & 2
mapping = (color = :coefname, y = :estimate))
plot_parallelcoordinates(
subset(results_plot, :channel => x -> x .<= 5);
mapping = (; color = :coefname),
)
```


## Normalization
On the first image, there is no normalization and the extremes of all axes are the same and equal to the max and min values across all chanells.
On the second image, there is a `minmax normalization``, so each axis has its own extremes based on the min and max of the data.

Typically, parallelplots are normalized per axis. Whether this makes sense for estimating channel x, we do not know.

```@example main
f = Figure()
plot_parallelcoordinates(
f[1, 1],
subset(results_plot, :channel => x -> x .< 10);
mapping = (; color = :coefname),
)
plot_parallelcoordinates(
f[2, 1],
subset(results_plot, :channel => x -> x .< 10);
mapping = (; color = :coefname),
normalize = :minmax,
)
f

!!! important
the following is still outdated...

## Column Mappings for PCPs

Since PCPs use a `DataFrame` as an input, the library needs to know the names of the columns used for plotting.
```

While there are multiple default values that are checked in that order if they exist in the `DataFrame`, a custom name might need to be choosen for:
## Labels
Use `ax_labels` to specify labels for the axes.

### y
Default is `(:y, :estimate, :yhat)`.
```@example main
plot_parallelcoordinates(
subset(results_plot, :channel => x -> x .< 5);
visual = (; color = :darkblue),
ax_labels = ["Fz", "Cz", "O1", "O2"],
)

### channel
Default is `:channel`.
```

### color
XXX Default is `:coef`.
## Tick labels
Specify tick labels on axis. There are four different options for the tick labels.

### time
Default is `:time`.
```@example main
f = Figure()
plot_parallelcoordinates(
f[1, 1],
subset(results_plot, :channel => x -> x .< 5);
ax_labels = ["Fz", "Cz", "O1", "O2"],
ax_ticklabels = :all,
normalize = :minmax,
) # all tick labels on all axis
plot_parallelcoordinates(
f[2, 1],
subset(results_plot, :channel => x -> x .< 5);
ax_ticklabels = :left,
normalize = :minmax,
) # tick labels on extremities + tickets on the left
plot_parallelcoordinates(
f[3, 1],
subset(results_plot, :channel => x -> x .< 5);
ax_ticklabels = :outmost,
normalize = :minmax,
) # show tick labels on extremities of axis

plot_parallelcoordinates(
f[4, 1],
subset(results_plot, :channel => x -> x .< 5);
ax_ticklabels = :none,
normalize = :minmax,
) # disable tick labels
f
```


## Bending the parallel plot
Bending the linescan be helpful to make them more visible.

```@example main
f = Figure()
plot_parallelcoordinates(f[1,1],
subset(results_plot, :channel=>x->x.<10))
plot_parallelcoordinates(f[2,1],
subset(results_plot, :channel=>x->x.<10), bend=true)
f

```

## Transparancy
```@example main
uf_5chan = example_data("UnfoldLinearModelMultiChannel")

f = Figure()
plot_parallelcoordinates(
f[1, 1],
uf_5chan;
mapping = (; color = :coefname),
layout = (; legend_position = :right),
visual=(; alpha=0.1)
)
plot_parallelcoordinates(
f[2, 1],
uf_5chan;
mapping = (; color = :coefname),
layout = (; legend_position = :right),
visual=(; alpha=0.9)
)
f

```
6 changes: 5 additions & 1 deletion src/UnfoldMakie.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module UnfoldMakie

import Makie.get_ticks
using Makie
#using CairoMakie
using AlgebraOfGraphics
Expand All @@ -17,6 +18,8 @@ using ColorTypes

using DocStringExtensions # for $SIGNATURES

using Interpolations # for parallelplot

using DataStructures
using DataFrames
using SparseArrays
Expand All @@ -27,6 +30,7 @@ using CoordinateTransformations # for 3D positions to 2D

import Makie.hidedecorations!
import Makie.hidespines!

import AlgebraOfGraphics.hidedecorations!
#import AlgebraOfGraphics.hidespines!

Expand Down Expand Up @@ -62,7 +66,7 @@ export plot_erpimage!
export plot_topoplot
export plot_topoplot!
export plot_parallelcoordinates
export plot_parallelcoordinates!

export plot_butterfly
export plot_butterfly!
export plot_circulareegtopoplot
Expand Down
Loading
Loading