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

Erp plot documentation #86

Merged
merged 28 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: UnfoldMakie
message: 'If you use this page, please cite it as below.'
type: software
authors:
- given-names: Benedikt
family-names: Ehinger
orcid: 'https://orcid.org/0000-0002-6276-3332'
- given-names: Sören
family-names: Döring
- given-names: Niklas
family-names: Gärtner
- given-names: Vladimir
family-names: Mikheev
orcid: 'https://orcid.org/0000-0002-4738-6655'
- given-names: René
family-names: Skukies
orcid: 'https://orcid.org/0000-0002-4124-4584'

identifiers:
- type: doi
value: 10.5281/zenodo.6531996
repository-code: 'https://github.com/unfoldtoolbox/UnfoldMakie.jl'
version: 0.3.5
date-released: '2023-10-24'
28 changes: 20 additions & 8 deletions docs/src/literate/tutorials/circTopo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,30 @@ using DataFrames

# # Generate data
# Generate a Dataframe. We need to specify the TopoPlot Positions either via position, or via labels (according to TopoPlots.jl)
data,pos = TopoPlots.example_data();
data, pos = TopoPlots.example_data();
dat = data[:, 240, 1]
df= DataFrame(
:estimate=>eachcol(Float64.(data[:,100:40:300,1])),
:circularVariable=>[0,50,80,120,180,210],
:time=>100:40:300)
df = flatten(df,:estimate);
df = DataFrame(
:estimate => eachcol(Float64.(data[:, 100:40:300, 1])),
:circularVariable => [0, 50, 80, 120, 180, 210],
:time => 100:40:300,
)
df = flatten(df, :estimate);

# # Our first plot!
# note how the plots are at the angles of circularVariable`
plot_circulareegtopoplot(df;positions=pos,axis=(;label="Sac Incoming"),predictor=:circularVariable)
plot_circulareegtopoplot(
df;
positions = pos,
axis = (; label = "Sac Incoming"),
predictor = :circularVariable,
)


# In case the bounding variable is not between 0 and 360, as here we use actually time, we have to specify it. e.g.
plot_circulareegtopoplot(df;positions=pos,axis=(;label="Time?!"),predictor=:time,extra=(;predictorBounds=[80,320]))
plot_circulareegtopoplot(
df;
positions = pos,
axis = (; label = "Time?!"),
predictor = :time,
predictorBounds = [80, 320],
)
28 changes: 20 additions & 8 deletions docs/src/literate/tutorials/circTopo.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,39 @@ using DataFrames
Generate a Dataframe. We need to specify the TopoPlot Positions either via position, or via labels (according to TopoPlots.jl)

````@example circTopo
data,pos = TopoPlots.example_data();
data, pos = TopoPlots.example_data();
dat = data[:, 240, 1]
df= DataFrame(
:estimate=>eachcol(Float64.(data[:,100:40:300,1])),
:circularVariable=>[0,50,80,120,180,210],
:time=>100:40:300)
df = flatten(df,:estimate);
df = DataFrame(
:estimate => eachcol(Float64.(data[:, 100:40:300, 1])),
:circularVariable => [0, 50, 80, 120, 180, 210],
:time => 100:40:300,
)
df = flatten(df, :estimate);
nothing #hide
````

# Our first plot!
note how the plots are at the angles of circularVariable`

````@example circTopo
plot_circulareegtopoplot(df;positions=pos,axis=(;label="Sac Incoming"),predictor=:circularVariable)
plot_circulareegtopoplot(
df;
positions = pos,
axis = (; label = "Sac Incoming"),
predictor = :circularVariable,
)
````

In case the bounding variable is not between 0 and 360, as here we use actually time, we have to specify it. e.g.

````@example circTopo
plot_circulareegtopoplot(df;positions=pos,axis=(;label="Time?!"),predictor=:time,extra=(;predictorBounds=[80,320]))
plot_circulareegtopoplot(
df;
positions = pos,
axis = (; label = "Time?!"),
predictor = :time,
predictorBounds = [80, 320],
)
````

---
Expand Down
47 changes: 25 additions & 22 deletions docs/src/literate/tutorials/erp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@ using UnfoldMakie

# ## Setup
# Let's generate some data and fit a model of a 2-level categorical and a continuous predictor with interaction.
data,evts = UnfoldSim.predef_eeg(;noiselevel=12,return_epoched=true)
data = reshape(data,(1,size(data)...))
f = @formula 0 ~ 1+condition+continuous
se_solver =(x,y)->Unfold.solver_default(x,y,stderror=true);

m = fit(UnfoldModel, Dict(Any=>(f,range(0,step=1/100,length=size(data,2)))), evts, data,solver=se_solver)
data, evts = UnfoldSim.predef_eeg(; noiselevel = 12, return_epoched = true)
data = reshape(data, (1, size(data)...))
f = @formula 0 ~ 1 + condition + continuous
se_solver = (x, y) -> Unfold.solver_default(x, y, stderror = true);

m = fit(
UnfoldModel,
Dict(Any => (f, range(0, step = 1 / 100, length = size(data, 2)))),
evts,
data,
solver = se_solver,
)
results = coeftable(m)
res_effects = effects(Dict(:continuous=>-5:0.5:5),m);
res_effects = effects(Dict(:continuous => -5:0.5:5), m);

# ## Plot the results
plot_erp(results; extra=(:stderror=>true,))
plot_erp(results; :stderror => true,)



Expand All @@ -42,22 +48,22 @@ plot_erp(results; extra=(:stderror=>true,))

# # Configuration for Line Plots

# ## extra
# `plot_erp(...;extra=(;<name>=<value>,...)`.
# ## key values
# `plot_erp(...; <name>=<value>,...)`.
# - categoricalColor (boolean, true) - in case of numeric `:color` column, is color a continuous or categorical variable?
# - categoricalGroup (boolean, true) - in case of numeric `:group` column, treat `:group` as categorical variable by default
# - stderror (boolean, false) - add an error-ribbon based on the `:stderror` column
# - pvalue (see below)

# Using some general configurations we can pretty up the default visualization. Here we use the following configuration:

plot_erp(res_effects;
mapping = (;y=:yhat,color=:continuous, group=:continuous),
extra=(;showLegend=true,
categoricalColor=false,
categoricalGroup=true),
legend = (;nbanks=2),
layout = (;legendPosition=:right))
plot_erp(
res_effects;
mapping = (; y = :yhat, color = :continuous, group = :continuous),
legend = (; nbanks = 2),
layout = (; legendPosition = :right),
showLegend = true, categoricalColor = false, categoricalGroup = true,
)



Expand All @@ -78,18 +84,15 @@ plot_erp(res_effects;
# coefname=["(Intercept)","condition: face"] # if coefname not specified, line should be black
# )
#
# plot_erp(results;extra= (;:pvalue=>pvals))
# plot_erp(results; :pvalue=>pvals)
# ### stderror (boolean)
# Indicating whether the plot should show a colored band showing lower and higher estimates based on the stderror.
# Default is `false`.
#
# previously we showed `:stderror`- but low/high is possible as well`
results.se_low = results.estimate .- 0.5
results.se_high = results.estimate .+ 0.15
plot_erp(select(results,Not(:stderror));extra= (;stderror=true))
plot_erp(select(results, Not(:stderror)); stderror = true)

# !!! note
# as in the above code,`:stderror` has precedence over `:se_low`/`:se_high`



47 changes: 27 additions & 20 deletions docs/src/literate/tutorials/erp.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,43 @@ using UnfoldMakie
Let's generate some data and fit a model of a 2-level categorical and a continuous predictor with interaction.

````@example erp
data,evts = UnfoldSim.predef_eeg(;noiselevel=12,return_epoched=true)
data = reshape(data,(1,size(data)...))
f = @formula 0 ~ 1+condition+continuous
se_solver =(x,y)->Unfold.solver_default(x,y,stderror=true);

m = fit(UnfoldModel, Dict(Any=>(f,range(0,step=1/100,length=size(data,2)))), evts, data,solver=se_solver)
data, evts = UnfoldSim.predef_eeg(; noiselevel = 12, return_epoched = true)
data = reshape(data, (1, size(data)...))
f = @formula 0 ~ 1 + condition + continuous
se_solver = (x, y) -> Unfold.solver_default(x, y, stderror = true);

m = fit(
UnfoldModel,
Dict(Any => (f, range(0, step = 1 / 100, length = size(data, 2)))),
evts,
data,
solver = se_solver,
)
results = coeftable(m)
res_effects = effects(Dict(:continuous=>-5:0.5:5),m);
res_effects = effects(Dict(:continuous => -5:0.5:5), m);
nothing #hide
````

## Plot the results

````@example erp
plot_erp(results; extra=(:stderror=>true,))
plot_erp(results; :stderror=>true,)
````

## Column Mappings for Line Plots
`plot_erp` use a `DataFrame` as an input, the library needs to know the names of the columns used for plotting.

There are multiple default values, that are checked in that order if they exist in the `DataFrame`, a custom name can be chosen using
`plot_erp(...;mapping=(; :y=:myEstimate)`
`plot_erp(...; mapping=(; :y=:myEstimate)`

:x Default is `(:x, :time)`.
:y Default is `(:y, :estimate, :yhat)`.
:color Default is `(:color, :coefname)`.

# Configuration for Line Plots

## extra
`plot_erp(...;extra=(;<name>=<value>,...)`.
## key variables
`plot_erp(...; <name>=<value>,...)`.
- categoricalColor (boolean, true) - in case of numeric `:color` column, is color a continuous or categorical variable?
- categoricalGroup (boolean, true) - in case of numeric `:group` column, treat `:group` as categorical variable by default
- stderror (boolean, false) - add an error-ribbon based on the `:stderror` column
Expand All @@ -63,13 +69,13 @@ There are multiple default values, that are checked in that order if they exist
Using some general configurations we can pretty up the default visualization. Here we use the following configuration:

````@example erp
plot_erp(res_effects;
mapping = (;y=:yhat,color=:continuous, group=:continuous),
extra=(;showLegend=true,
categoricalColor=false,
categoricalGroup=true),
legend = (;nbanks=2),
layout = (;legendPosition=:right))
plot_erp(
res_effects;
mapping = (; y = :yhat, color = :continuous, group = :continuous),
legend = (; nbanks = 2),
layout = (; legendPosition = :right),
showLegend = true, categoricalColor = false, categoricalGroup = true,
)
````

In the following we will use this "pretty" line plot as a basis for looking into configuration options.
Expand All @@ -91,7 +97,8 @@ pvals = DataFrame(
# )
````

plot_erp(results;extra= (;:pvalue=>pvals))
plot_erp(results; :pvalue=>pvals)

### stderror (boolean)
Indicating whether the plot should show a colored band showing lower and higher estimates based on the stderror.
Default is `false`.
Expand All @@ -101,7 +108,7 @@ previously we showed `:stderror`- but low/high is possible as well`
````@example erp
results.se_low = results.estimate .- 0.5
results.se_high = results.estimate .+ 0.15
plot_erp(select(results,Not(:stderror));extra= (;stderror=true))
plot_erp(select(results, Not(:stderror)); stderror=true)
````

!!! note
Expand Down
10 changes: 6 additions & 4 deletions docs/src/tutorials/butterfly.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ We filter the data to make it more clearly represented:
```@example main
include("../../example_data.jl")
df, pos = example_data("TopoPlots.jl")
first(df,3)
first(df, 3)
```

## Plot Butterfly Plots
Expand All @@ -37,7 +37,7 @@ plot_butterfly(df; positions=pos)

## Column Mappings for Butterfly Plots

Since butterfly plots use a `DataFrame` as input, the library needs to know the names of the columns used for plotting. You can set these mapping values by calling `plot_butterfly(...; mapping=(;:x=:time,))`, that is, by specifying a `NamedTuple` (note the `;` right after the opening parentheses).
Since butterfly plots use a `DataFrame` as input, the library needs to know the names of the columns used for plotting. You can set these mapping values by calling `plot_butterfly(...; mapping=(; :x=:time,))`, that is, by specifying a `NamedTuple` (note the `;` right after the opening parentheses).

For more information on mapping values, see the [Mapping Data](@ref config_mapping) section of the documentation.

Expand All @@ -56,8 +56,10 @@ Default is `(:labels, :label, :topoLabels, :sensor, :nothing)`

## Configurations for Butterfly Plots

Here we look into possible options for configuring the butterfly plot visualization using `(...; extra=(<name>=<value>, ...)`.
This is the list of unique configuration (extraData):

Here we look into possible options for configuring the butterfly plot visualization using `(...; <name>=<value>, ...)`.
This is the list of unique configuration (key values):


- topoLegend (boolean)

Expand Down
10 changes: 5 additions & 5 deletions docs/src/tutorials/designmatrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ The following code will result in the default configuration.
plot_designmatrix(designmatrix(uf))
```

# `plot_designmatrix(...; extra=(<name>=<value>, ...)`.
# kwargs `plot_designmatrix(...; ...)`.


- sortData (boolean,false) - Indicating whether the data is sorted; using sortslices() of Base Julia.


In order to make the designmatrix easier to read, you may want to sort it.
```
plot_designmatrix(designmatrix(uf);extra=(;sortData=true))
plot_designmatrix(designmatrix(uf); sortData=true)
```

- standardizeData (boolean,false) - Indicating whether the data is standardized, mapping the values between 0 and 1.

- standardizeData (boolean, false) - Indicating whether the data is standardized, mapping the values between 0 and 1.
- xTicks (number, nothing)

- xTicks (number,nothing)
Indicating the number of labels on the x-axis. Behavior if specified in configuration:
- xTicks = 0: no labels are placed.
- xTicks = 1: first possible label is placed.
Expand Down
6 changes: 3 additions & 3 deletions docs/src/tutorials/erpimage.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ Since ERP images use a `Matrix` as an input, the library does not need any infor
## extra=(;)
- erpBlur (number, 10) - Is a number indicating how much blur is applied to the image; using Gaussian blur of the ImageFiltering module. Negative values deactivate the blur.

- sortData (boolean, false) - Indicating whether the data is sorted; using sortperm() of Base Julia
- sortvalues - Indicating whether the data is sorted; using sortperm() of Base Julia
(sortperm() computes a permutation of the array's indices that puts the array into sorted order).

- ploterp (bool, false) - Indicating whether the plot should add a line plot below the ERP image, showing the mean of the data. If limits are set in the axis values both plots will be aligned.
- meanPlot (bool, false) - Indicating whether the plot should add a line plot below the ERP image, showing the mean of the data. If limits are set in the axis values both plots will be aligned.

```@example main
plot_erpimage(data;
extra = (ploterp = true,),
meanPlot = true,
colorbar = (label = "Voltage [µV]",),
visual = (colormap = :viridis, colorrange = (-40, 40)))

Expand Down
2 changes: 1 addition & 1 deletion src/UnfoldMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import AlgebraOfGraphics.hidedecorations!

include("plotconfig.jl")

include("eeg-series.jl")
include("eeg_series.jl")
include("plot_topoplotseries.jl")

include("plot_erp.jl")
Expand Down
Loading
Loading