GigRidges (gig_ridges v0.1.0)

Copy Markdown View Source

Ridgeline plots for Giggly: ridges along x, one above each baseline, as joy plots draw them.

geom_ridgeline/3 draws ridges of the heights a table gives, and geom_vridgeline/3 of the widths it gives, running up y; stat_density_ridges/3 and geom_density_ridges/3 estimate each group's density along x and draw it as a ridge, and geom_density_ridges2/3 draws it outlined round its whole border; geom_density_line/3 draws one density over a baseline of 0 the way the ridges are drawn; stat_binline/3 draws each group's histogram as a ridge; geom_ridgeline_gradient/3 and geom_density_ridges_gradient/3 draw a ridge whose fill varies along it. Each adds a layer to a Giggly.Plot, through Giggly.Plot.layer/3, so it takes Giggly's own options for the marks (fill:, alpha:, colour:, linewidth:, linetype:, position:) beside its own, and its mistakes are refused naming it. cyclical_scale/3 and the scale_*_cyclical/2 functions give the ridges values in turn, as alternating fills, through Giggly's manual scales, and theme_ridges/2 draws everything but the marks plainly, for ridgeline plots.

iex> frame =
...>   GigDatasets.mpg()
...>   |> Giggly.Plot.new(%{x: :hwy, y: :class})
...>   |> GigRidges.geom_density_ridges()
...>   |> Giggly.layer_data()
iex> Giggly.DataFrame.row_count(frame)
3584

Summary

Types

A layer's mapping, as Giggly.Plot's layer functions take one.

Functions

Gives the plot one cyclical scale serving every aesthetic aesthetics names, replacing any scale that served one of them: values:, a list, handed to the data's values in the order the scale shows them and started again at the first once they run out, so the ridges take turns, as values: ["red", "blue"] fills five ridges red, blue, red, blue and red.

Adds a layer of density lines: each group's density along x, estimated by Giggly's density stat (Giggly.Plot.geom_density/3's), drawn as a ridgeline over a baseline of 0 (GigRidges.DensityLine), filled grey70 and outlined in black along its top, where Giggly.Plot.geom_density/3 is filled with nothing.

Adds the layer geom_density_ridges/3 adds, from the same mapping and options, but each ridge outlined round its whole border, its baseline and sides too, not along its top alone (GigRidges.DensityRidgeline2).

Adds the layer stat_density_ridges/3 adds, from the same mapping and options, but its points under jittered_points: set up their ridges at random (GigRidges.PointsSina) unless another position: is given, where the stat's stay on their baselines.

Adds the layer geom_density_ridges/3 adds, from the same mapping and options, but a ridge whose fill varies along it drawn in pieces of one fill each (GigRidges.DensityRidgelineGradient), as %{fill: {:after_stat, [:x]}} fills each ridge by where along it each place is; and gradient_lwd:, each piece's outline in its own fill, 0.5 unless given.

Adds a layer of ridgelines: each group a ridge along x, its baseline its y and its top scale times its height above it (GigRidges.Ridgeline), the rows drawn as they are.

Adds the layer geom_ridgeline/3 adds, from the same mapping and options, but a ridge whose fill varies along it drawn in pieces of one fill each (GigRidges.RidgelineGradient), as %{fill: :x} fills each ridge by where along it each point is.

Adds a layer of vertical ridgelines: each group a ridge up y, its baseline its x and its outer edge scale times its width beyond it (GigRidges.VRidgeline), the rows drawn as they are.

Gives the plot a cyclical alpha scale, replacing any alpha scale it had: cyclical_scale/3 serving :alpha.

The cyclical colour scale scale_colour_cyclical/2 gives, under the other spelling.

Gives the plot a cyclical colour scale, replacing any colour scale it had: cyclical_scale/3 serving :color.

Gives the plot a cyclical fill scale, replacing any fill scale it had: cyclical_scale/3 serving :fill.

Gives the plot a cyclical line type scale, replacing any line type scale it had: cyclical_scale/3 serving :linetype.

Gives the plot a cyclical line width scale, replacing any line width scale it had: cyclical_scale/3 serving :linewidth.

Gives the plot a cyclical size scale, replacing any size scale it had: cyclical_scale/3 serving :size.

Adds a layer of binned ridges: each group's values counted in bins along x, every group of a panel in the panel's bins (GigRidges.Binline), drawn by the density ridges' geom as a histogram's outline above its y, so the panel's greatest density reaches the next baseline at a scale: of 1.

Adds a layer of density ridges: each group's density along x, estimated with one bandwidth each panel's groups share (GigRidges.DensityRidges), drawn as a ridgeline above its y, so the panel's greatest density reaches the next baseline at a scale: of 1.

Draws everything but the marks plainly, for ridgeline plots: nothing behind the marks, light grey grid lines and ticks, black text, the axes' titles at the far ends of their axes and the y axis's tick labels on their baselines, so each ridge's name sits on it.

Types

mapping()

@type mapping() :: %{optional(atom()) => term()}

A layer's mapping, as Giggly.Plot's layer functions take one.

Functions

cyclical_scale(plot, aesthetics, options)

@spec cyclical_scale(Giggly.Plot.t(), atom() | [atom()], keyword()) :: Giggly.Plot.t()

Gives the plot one cyclical scale serving every aesthetic aesthetics names, replacing any scale that served one of them: values:, a list, handed to the data's values in the order the scale shows them and started again at the first once they run out, so the ridges take turns, as values: ["red", "blue"] fills five ridges red, blue, red, blue and red.

It is Giggly's manual scale (Giggly.Plot.scale_discrete_manual/3), its values repeated, and takes its options, which check every value given as the aesthetics they serve check one, and its aesthetics, :color and :fill together, any of :alpha, :size and :linewidth, or :linetype, :colour spelled either way. Its legend is drawn only under guide: :legend, where breaks: chooses its keys, each drawn as its own value is, and labels: labels them, as breaks: ["a", "b"], labels: ["odd", "even"] labels a cycle of two. Its values are repeated to a thousand, or to as many as limits: gives, and a scale showing more refuses the plot, as a manual scale given too few values does. Raises ArgumentError for values: that are not a list of one value or more.

iex> frame =
...>   %{"v" => [0, 1, 2, 0, 1, 2, 0, 1, 2], "g" => ~w(a a a b b b c c c)}
...>   |> Giggly.Plot.new(%{x: :v, y: :g, fill: :g, colour: :g})
...>   |> GigRidges.geom_density_ridges(bandwidth: 1)
...>   |> GigRidges.cyclical_scale([:fill, :colour], values: ["red", "blue"])
...>   |> Giggly.layer_data()
iex> frame |> Giggly.DataFrame.pull(:fill) |> Enum.dedup()
["#FF0000", "#0000FF", "#FF0000"]

geom_density_line(plot, mapping_or_options \\ %{}, options \\ [])

@spec geom_density_line(Giggly.Plot.t(), mapping() | keyword(), keyword()) ::
  Giggly.Plot.t()

Adds a layer of density lines: each group's density along x, estimated by Giggly's density stat (Giggly.Plot.geom_density/3's), drawn as a ridgeline over a baseline of 0 (GigRidges.DensityLine), filled grey70 and outlined in black along its top, where Giggly.Plot.geom_density/3 is filled with nothing.

It needs :x, and takes the density stat's options, bw:, adjust:, kernel:, n:, trim: and bounds:, beside Giggly's options for the marks; a mapped y reads another of the stat's variables, as {:after_stat, [:count]}.

geom_density_ridges2(plot, mapping_or_options \\ %{}, options \\ [])

@spec geom_density_ridges2(Giggly.Plot.t(), mapping() | keyword(), keyword()) ::
  Giggly.Plot.t()

Adds the layer geom_density_ridges/3 adds, from the same mapping and options, but each ridge outlined round its whole border, its baseline and sides too, not along its top alone (GigRidges.DensityRidgeline2).

geom_density_ridges(plot, mapping_or_options \\ %{}, options \\ [])

@spec geom_density_ridges(Giggly.Plot.t(), mapping() | keyword(), keyword()) ::
  Giggly.Plot.t()

Adds the layer stat_density_ridges/3 adds, from the same mapping and options, but its points under jittered_points: set up their ridges at random (GigRidges.PointsSina) unless another position: is given, where the stat's stay on their baselines.

geom_density_ridges_gradient(plot, mapping_or_options \\ %{}, options \\ [])

@spec geom_density_ridges_gradient(Giggly.Plot.t(), mapping() | keyword(), keyword()) ::
  Giggly.Plot.t()

Adds the layer geom_density_ridges/3 adds, from the same mapping and options, but a ridge whose fill varies along it drawn in pieces of one fill each (GigRidges.DensityRidgelineGradient), as %{fill: {:after_stat, [:x]}} fills each ridge by where along it each place is; and gradient_lwd:, each piece's outline in its own fill, 0.5 unless given.

geom_ridgeline(plot, mapping_or_options \\ %{}, options \\ [])

@spec geom_ridgeline(Giggly.Plot.t(), mapping() | keyword(), keyword()) ::
  Giggly.Plot.t()

Adds a layer of ridgelines: each group a ridge along x, its baseline its y and its top scale times its height above it (GigRidges.Ridgeline), the rows drawn as they are.

It needs :x, :y and :height, and takes the ridgeline's options, scale: and min_height:, beside Giggly's options for the marks; each may be mapped instead, giving each point its own, an option given beating its mapping.

iex> frame =
...>   %{"x" => [1, 2, 3, 1, 2, 3], "y" => [0, 0, 0, 1, 1, 1], "h" => [0.2, 0.9, 0.3, 0.5, 0.4, 0.1]}
...>   |> Giggly.Plot.new(%{x: :x, y: :y, height: :h, group: :y})
...>   |> GigRidges.geom_ridgeline(scale: 2)
...>   |> Giggly.layer_data()
iex> Giggly.DataFrame.pull(frame, :ymax)
[0.4, 1.8, 0.6, 2.0, 1.8, 1.2]

geom_ridgeline_gradient(plot, mapping_or_options \\ %{}, options \\ [])

@spec geom_ridgeline_gradient(Giggly.Plot.t(), mapping() | keyword(), keyword()) ::
  Giggly.Plot.t()

Adds the layer geom_ridgeline/3 adds, from the same mapping and options, but a ridge whose fill varies along it drawn in pieces of one fill each (GigRidges.RidgelineGradient), as %{fill: :x} fills each ridge by where along it each point is.

It takes gradient_lwd: beside the ridgeline's options: the width of each piece's outline in its own fill, in R's line-width units, 0.5 unless given, so the seams between pieces do not show.

geom_vridgeline(plot, mapping_or_options \\ %{}, options \\ [])

@spec geom_vridgeline(Giggly.Plot.t(), mapping() | keyword(), keyword()) ::
  Giggly.Plot.t()

Adds a layer of vertical ridgelines: each group a ridge up y, its baseline its x and its outer edge scale times its width beyond it (GigRidges.VRidgeline), the rows drawn as they are.

It needs :x, :y and :width, and takes scale: and min_width: beside Giggly's options for the marks; each may be mapped instead, giving each point its own, an option given beating its mapping.

iex> frame =
...>   %{"x" => [0, 0, 0, 1, 1, 1], "y" => [1, 2, 3, 1, 2, 3], "w" => [0.2, 0.9, 0.3, 0.5, 0.4, 0.1]}
...>   |> Giggly.Plot.new(%{x: :x, y: :y, width: :w, group: :x})
...>   |> GigRidges.geom_vridgeline(scale: 2)
...>   |> Giggly.layer_data()
iex> Giggly.DataFrame.pull(frame, :xmax)
[0.4, 1.8, 0.6, 2.0, 1.8, 1.2]

scale_alpha_cyclical(plot, options)

@spec scale_alpha_cyclical(Giggly.Plot.t(), keyword()) :: Giggly.Plot.t()

Gives the plot a cyclical alpha scale, replacing any alpha scale it had: cyclical_scale/3 serving :alpha.

scale_color_cyclical(plot, options)

@spec scale_color_cyclical(Giggly.Plot.t(), keyword()) :: Giggly.Plot.t()

The cyclical colour scale scale_colour_cyclical/2 gives, under the other spelling.

scale_colour_cyclical(plot, options)

@spec scale_colour_cyclical(Giggly.Plot.t(), keyword()) :: Giggly.Plot.t()

Gives the plot a cyclical colour scale, replacing any colour scale it had: cyclical_scale/3 serving :color.

scale_fill_cyclical(plot, options)

@spec scale_fill_cyclical(Giggly.Plot.t(), keyword()) :: Giggly.Plot.t()

Gives the plot a cyclical fill scale, replacing any fill scale it had: cyclical_scale/3 serving :fill.

iex> frame =
...>   %{"v" => [0, 1, 2, 0, 1, 2, 0, 1, 2], "g" => ~w(a a a b b b c c c)}
...>   |> Giggly.Plot.new(%{x: :v, y: :g, fill: :g})
...>   |> GigRidges.geom_density_ridges(bandwidth: 1)
...>   |> GigRidges.scale_fill_cyclical(values: ["red", "blue"])
...>   |> Giggly.layer_data()
iex> frame |> Giggly.DataFrame.pull(:fill) |> Enum.dedup()
["#FF0000", "#0000FF", "#FF0000"]

scale_linetype_cyclical(plot, options)

@spec scale_linetype_cyclical(Giggly.Plot.t(), keyword()) :: Giggly.Plot.t()

Gives the plot a cyclical line type scale, replacing any line type scale it had: cyclical_scale/3 serving :linetype.

scale_linewidth_cyclical(plot, options)

@spec scale_linewidth_cyclical(Giggly.Plot.t(), keyword()) :: Giggly.Plot.t()

Gives the plot a cyclical line width scale, replacing any line width scale it had: cyclical_scale/3 serving :linewidth.

scale_size_cyclical(plot, options)

@spec scale_size_cyclical(Giggly.Plot.t(), keyword()) :: Giggly.Plot.t()

Gives the plot a cyclical size scale, replacing any size scale it had: cyclical_scale/3 serving :size.

stat_binline(plot, mapping_or_options \\ %{}, options \\ [])

@spec stat_binline(Giggly.Plot.t(), mapping() | keyword(), keyword()) ::
  Giggly.Plot.t()

Adds a layer of binned ridges: each group's values counted in bins along x, every group of a panel in the panel's bins (GigRidges.Binline), drawn by the density ridges' geom as a histogram's outline above its y, so the panel's greatest density reaches the next baseline at a scale: of 1.

It needs :x and :y, and takes the stat's binwidth:, bins:, center:, boundary:, breaks:, closed:, pad: and draw_baseline:, and the density ridges' geom's scale:, rel_min_height: and panel_scaling:, beside Giggly's options for the marks.

stat_density_ridges(plot, mapping_or_options \\ %{}, options \\ [])

@spec stat_density_ridges(Giggly.Plot.t(), mapping() | keyword(), keyword()) ::
  Giggly.Plot.t()

Adds a layer of density ridges: each group's density along x, estimated with one bandwidth each panel's groups share (GigRidges.DensityRidges), drawn as a ridgeline above its y, so the panel's greatest density reaches the next baseline at a scale: of 1.

It needs :x and :y, y most often a discrete column whose values name the ridges, and takes the stat's bandwidth:; from:, to: and n:, the span and number of places each density is read at; and quantile_lines:, quantiles: and quantile_fun:, a line up each ridge at each of its group's quantiles, or under calc_ecdf: each place's ecdf and band alone; jittered_points:, a point under each ridge at each of its group's values, drawn in the point_* given, on its baseline unless the layer's position moves it, as GigRidges.PointsSina, GigRidges.PointsJitter and GigRidges.PointsRaincloud do; the lines drawn in the vline_color:, vline_width: and vline_linetype: given, over the ridge's own; and the density ridges' geom's (GigRidges.DensityRidgeline) beside Giggly's options for the marks: scale:, 1.8 unless given or mapped, so neighbouring ridges overlap; panel_scaling:, whether each panel's tallest ridge or the layer's reaches the next baseline; and rel_min_height:, the share of the layer's greatest height below which a point is left out, in place of the ridgeline's min_height:. A scale or rel_min_height mapped is each ridge's own, and a weight mapped weighs each row's share of its group's density.

theme_ridges(plot_or_options \\ [], options \\ [])

@spec theme_ridges(Giggly.Plot.t() | keyword(), keyword()) :: Giggly.Plot.t() | term()

Draws everything but the marks plainly, for ridgeline plots: nothing behind the marks, light grey grid lines and ticks, black text, the axes' titles at the far ends of their axes and the y axis's tick labels on their baselines, so each ridge's name sits on it.

Given a plot, it replaces the plot's theme whole, as Giggly.Plot.theme_gray/2 does; given its options alone, it returns the theme, to be kept and given to plots with Giggly.Plot.theme/2. It is Giggly's default theme at a base size of font_size:, with its settings laid over it, so a later Giggly.Plot.theme/2 call is laid over it in turn.

Options

  • :font_size - How big its text is, in points: every size, spacing and margin follows from it. The default value is 14.

  • :font_family (String.t/0) - The font its text is drawn in, by name; "", the default sans-serif. The default value is "".

  • :line_size - How wide its grid lines and ticks are, in millimetres. The default value is 0.5.

  • :grid (boolean/0) - Whether the major grid lines and the y axis's ticks are drawn. The default value is true.

  • :center_axis_labels (boolean/0) - Whether the axes' titles are centred on their axes, not at their far ends. The default value is false.

    iex> svg = ...> %{"v" => [0, 1, 2, 0, 1, 2], "g" => ~w(a a a b b b)} ...> |> Giggly.Plot.new(%{x: :v, y: :g}) ...> |> GigRidges.geom_density_ridges(bandwidth: 1) ...> |> GigRidges.theme_ridges(grid: false) ...> |> Giggly.to_svg() ...> |> IO.iodata_to_binary() iex> svg =~ "#E5E5E5" false