Parallel Coordinates
Parallel Coordinates Plot (PCP) is a plot type used to visualize EEG activity for some channels. It can fully represent condition and channel dimensions using lines. It can also partially represent time and trials.
Each vertical axis represents a voltage level for a channel. Each line represents a trial, each colour represents a condition.
Setup
Package loading
using Unfold
using UnfoldMakie
using DataFrames
using CairoMakie
Data generation
include("../../../example_data.jl")
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);
Plot PCPs
plot_parallelcoordinates(
subset(results_plot, :channel => x -> x .<= 5);
mapping = (; color = :coefname),
ax_labels = ["FP1", "F3", "F7", "FC3", "C3"],
)
Additional features
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, parallel plots are normalized per axis. Whether this makes sense for estimating channel x, we do not know.
f = Figure()
plot_parallelcoordinates(
f[1, 1],
subset(results_plot, :channel => x -> x .< 10);
mapping = (; color = :coefname),
axis = (; title = "normalize = nothing"),
)
plot_parallelcoordinates(
f[2, 1],
subset(results_plot, :channel => x -> x .< 10);
mapping = (; color = :coefname),
normalize = :minmax,
axis = (; title = "normalize = :minmax"),
)
f
Color schemes
Use only categorical with high contrast between adjacent colors. More: change colormap.
f = Figure()
plot_parallelcoordinates(
f[1, 1],
subset(results_plot, :channel => x -> x .<= 5);
mapping = (; color = :coefname),
visual = (; colormap = :tab10),
axis = (; title = "colormap = tab10"),
)
plot_parallelcoordinates(
f[2, 1],
subset(results_plot, :channel => x -> x .<= 5);
mapping = (; color = :coefname),
visual = (; colormap = :Accent_3),
axis = (; title = "colormap = Accent_3"),
)
f
Labels
Use ax_labels
to specify labels for the axes.
plot_parallelcoordinates(
subset(results_plot, :channel => x -> x .< 5);
visual = (; color = :darkblue),
ax_labels = ["Fz", "Cz", "O1", "O2"],
)
Tick labels
Specify tick labels on axis. There are four different options for the tick labels.
f = Figure(size = (400, 800))
plot_parallelcoordinates(
f[1, 1],
subset(results_plot, :channel => x -> x .< 5, :time => x -> x .< 0);
ax_labels = ["Fz", "Cz", "O1", "O2"],
ax_ticklabels = :all,
normalize = :minmax,
axis = (; title = "ax_ticklabels = :all"),
) # show all ticks on all axes
plot_parallelcoordinates(
f[2, 1],
subset(results_plot, :channel => x -> x .< 5, :time => x -> x .< 0);
ax_labels = ["Fz", "Cz", "O1", "O2"],
ax_ticklabels = :left,
normalize = :minmax,
axis = (; title = "ax_ticklabels = :left"),
) # show all ticks on the left axis, but only extremities on others
plot_parallelcoordinates(
f[3, 1],
subset(results_plot, :channel => x -> x .< 5, :time => x -> x .< 0);
ax_labels = ["Fz", "Cz", "O1", "O2"],
ax_ticklabels = :outmost,
normalize = :minmax,
axis = (; title = "ax_ticklabels = :outmost"),
) # show ticks on extremities of all axes
plot_parallelcoordinates(
f[4, 1],
subset(results_plot, :channel => x -> x .< 5, :time => x -> x .< 0);
ax_labels = ["Fz", "Cz", "O1", "O2"],
ax_ticklabels = :none,
normalize = :minmax,
axis = (; title = "ax_ticklabels = :none"),
) # disable all ticks
f
Bending the parallel plot
Bending the linescan be helpful to make them more visible.
f = Figure()
plot_parallelcoordinates(
f[1, 1],
subset(results_plot, :channel => x -> x .< 10),
axis = (; title = "bend = false"),
)
plot_parallelcoordinates(
f[2, 1],
subset(results_plot, :channel => x -> x .< 10),
bend = true,
axis = (; title = "bend = true"),
)
f
Transparancy
uf_5chan = example_data("UnfoldLinearModelMultiChannel")
f = Figure()
plot_parallelcoordinates(
f[1, 1],
uf_5chan;
mapping = (; color = :coefname),
visual = (; alpha = 0.1),
axis = (; title = "alpha = 0.1"),
)
plot_parallelcoordinates(
f[2, 1],
uf_5chan,
mapping = (; color = :coefname),
visual = (; alpha = 0.9),
axis = (; title = "alpha = 0.9"),
)
f
Configurations of Parallel coordinates plot
UnfoldMakie.plot_parallelcoordinates
— Functionplot_parallelcoordinates(data::Union{DataFrame, AbstractMatrix}; kwargs...)
plot_parallelcoordinates!(f::Union{GridPosition, GridLayout, Figure}, data::Union{DataFrame, AbstractMatrix}; kwargs)
Plot a PCP (parallel coordinates plot).
Dimensions: conditions, channels, time, trials.
Arguments:
f::Union{GridPosition, GridLayout, Figure}
Figure
,GridLayout
, orGridPosition
to draw the plot.data::Union{DataFrame, AbstractMatrix}
Data for the plot visualization.
Keyword arguments (kwargs)
normalize::Symbol = nothing
If:minmax
, normalize each axis to their respective min-max range.ax_labels::Vector{String} = nothing
Specify axis labels.
Should be a vector of labels with length equal to the number of uniquemapping.x
values.
Example:ax_labels = ["Fz", "Cz", "O1", "O2"]
.ax_ticklabels::Symbol = :outmost
Specify tick labels on axis.:all
- show all labels on all axes.:left
- show all labels on the left axis, but only min and max on others.:outmost
- show labels on min and max of all other axes.:none
- remove all labels.
bend::Bool = false
Change straight lines between the axes to curved ("bent") lines using spline interpolation.
Note: While this makes the plot look cool, it is not generally recommended to bent the lines, as interpretation suffers, and the resulting visualizations can be potentially missleading.visual.alpha::Number = 0.5
Change of line transparency.
Defining the axes
mapping.x = :channel, mapping.y = :estimate
.
Overwrite what should be on the x and the y axes.mapping.color = :colorcolumn
Split conditions by color. The default color is:black
.
Shared plot configuration options
The shared plot options can be used as follows: type = (; key = value, ...))
.
For example, plot_x(...; colorbar = (; vertical = true, label = "Test"))
.
Multiple defaults will be cycled until match.
Placing ;
is important!
figure = NamedTuple() - use kwargs...
of Makie.Figure
axis = (xlabel = "Channels", ylabel = "Time", title = "") - use kwargs...
of Makie.Axis
layout = (show_legend = true, use_colorbar = true) - check this page
mapping = (x = :channel, y = (:estimate, :yhat, :y)) - use any mapping from AlgebraOfGraphics
visual = (colormap = ColorTypes.RGBA{Float32}[RGBA{Float32}(0.0f0,0.44705883f0,0.69803923f0,1.0f0), RGBA{Float32}(0.9019608f0,0.62352943f0,0.0f0,1.0f0), RGBA{Float32}(0.0f0,0.61960787f0,0.4509804f0,1.0f0), RGBA{Float32}(0.8f0,0.4745098f0,0.654902f0,1.0f0), RGBA{Float32}(0.3372549f0,0.7058824f0,0.9137255f0,1.0f0), RGBA{Float32}(0.8352941f0,0.36862746f0,0.0f0,1.0f0), RGBA{Float32}(0.9411765f0,0.89411765f0,0.25882354f0,1.0f0)], color = :black, alpha = 0.3) - use kwargs...
of Makie.lines
legend = (orientation = :vertical, tellwidth = true, tellheight = false, halign = :right, valign = :center, title = "Conditions", merge = true, framevisible = false) - use kwargs...
of Makie.Legend
colorbar = (vertical = true, tellwidth = true, tellheight = false, labelrotation = -1.5707963267948966) - use kwargs...
of Makie.Colorbar
Return Value: Figure
displaying the Parallel coordinates plot.
This page was generated using Literate.jl.