Parallel Coordinates

Parallel Coordinates Plot (PCP) is a plot type used to visualize EEG activity for some channels. It can fully represent state and channel dimensions using lines. It can also partially represent time or trials Y-axis represents time points, vertical axes represent channels, while lines show voltage changes.

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),
)
Example block output

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, parallelplots 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
Example block output

Color schemes

Use only categorical with high contrast between adjacent colors. More: https://docs.makie.org/stable/explanations/colors/index.html

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
Example block output

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"],
)
Example block output

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
Example block output

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
Example block output

Transparancy

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),
    axis = (; title = "alpha = 0.1"),
)
plot_parallelcoordinates(
    f[2, 1],
    uf_5chan,
    mapping = (; color = :coefname),
    layout = (; legend_position = :right),
    visual = (; alpha = 0.9),
    axis = (; title = "alpha = 0.9"),
)
f
Example block output

Configurations of Parallel coordinates plot

UnfoldMakie.plot_parallelcoordinatesFunction
plot_parallelcoordinates(f::Union{GridPosition, GridLayout, Figure}, data::DataFrame; kwargs)

Plot a PCP (parallel coordinates plot).

Arguments:

  • f::Union{GridPosition, GridLayout, Figure} Figure, GridLayout, or GridPosition to draw the plot.
  • data::Union{DataFrame, Vector{Float32}}
    Data for the plot visualization.

Keyword argumets (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 unique mapping.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(...; layout = (; show_legend = true, legend_position = :right)).
Multiple defaults will be cycled until match.

Placing ; is important!

figure = NamedTuple() - use kwargs... of Makie.Figure

axis = (ylabel = "Time", title = "") - use kwargs... of Makie.Axis

layout = (show_legend = true, legend_position = :right, xlabelFromMapping = :x, ylabelFromMapping = :y, use_colorbar = false)

mapping = (x = :channel, y = (:estimate, :yhat, :y))

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, title = "Conditions", merge = true, framevisible = false) - use kwargs... of Makie.Legend

colorbar = (vertical = true, tellwidth = true, tellheight = false) - use kwargs... of Makie.Colorbar

Return Value: Figure displaying the Parallel coordinates plot.

source

This page was generated using Literate.jl.