Position adjustments: layer_positions
Mix.install([
{:giggly, path: Path.join(__DIR__, "..")},
{:kino, "~> 0.19"}
])
About this notebook
ggplot2's reference page for
layer_positions has no
examples, so this notebook says only what the page describes and where Giggly stands.
A layer's position adjusts where its marks sit, mostly to keep them from overlapping: dodging sets
them side by side, stacking piles them up, filling scales each pile to a proportion, jittering adds
random noise and nudging offsets them by a fixed distance. ggplot2 takes a layer's position from a
geom's default, as a string (position = "jitter"), as a position_*() function, which also
carries its options, or through layer(); for many layers it is position_identity(), which leaves
them where they are. Giggly takes a layer's position by name, position: :jitter, or by name with
its options in a tuple, position: {:jitter, seed: 1}, where ggplot2 calls a position_*()
function. Every layer function takes the positions that can move its marks, as ggplot2's do:
:identity, stacking (:stack or {:stack, options}), filling (:fill or {:fill, options},
as position_fill() does), dodging (:dodge or {:dodge, options}, and :dodge2 or
{:dodge2, options}, as position_dodge2() does), jittering (:jitter or {:jitter, options}),
jittering beside dodging (:jitterdodge or {:jitterdodge, options}, as position_jitterdodge()
does) and nudging (:nudge). Marks with no width of their own, such as points, text and line ranges,
are dodged, either way, only within a width given; box plots and rectangles are neither stacked, filled nor
jittered, and horizontal and vertical lines are only nudged. Bars and histograms stack by default, as do
Giggly.Plot.geom_area/3, and box plots dodge as position_dodge2() does;
Giggly.Plot.geom_jitter/3 jitters its points, and Giggly.Plot.geom_text/3 nudges every label,
as ggplot2's geom_text() does. A nudged layer moves by its nudge_x: and nudge_y: options or a
mapped nudge_x and nudge_y, as ggplot2 4.0's do, so :nudge takes no options, where
position_nudge() also takes x and y. Not in Giggly yet: layer().