Powered by AppSignal & Oban Pro

Geoms: layer_geoms

notebooks/layer_geoms.livemd

Geoms: layer_geoms

Mix.install([
  {:giggly, path: Path.join(__DIR__, "..")},
  {:kino, "~> 0.19"}
  ])

About this notebook

ggplot2's reference page for layer_geoms has no examples, so this notebook says only what the page describes and where Giggly stands.

A ggplot2 layer has two main parts: its geom, which decides how the data is displayed, and its stat, which decides what is displayed. A layer's geom can be given in five ways: by the geom's own function, such as geom_area(); as a stat's default; by name, as a string given to a stat; as the geom's ggproto object; or to layer() itself. A geom turns the layer's data into graphical primitives, such as points, lines, rectangles and polygons, styled by aesthetics such as colour, fill and linewidth. Many geoms abstract over others, as a ribbon is a special polygon and an area a special ribbon, and some compose several, as a boxplot is lines, rectangles and points. Giggly adds a layer with a function for each geom: Giggly.Plot.geom_point/3, Giggly.Plot.geom_count/3, Giggly.Plot.geom_bar/3, which counts with ggplot2's stat_count(), Giggly.Plot.geom_col/3, Giggly.Plot.geom_histogram/3 and Giggly.Plot.geom_freqpoly/3, which bin with stat_bin(), Giggly.Plot.geom_boxplot/3, Giggly.Plot.geom_path/3, Giggly.Plot.geom_line/3, Giggly.Plot.geom_rect/3, Giggly.Plot.geom_text/3, Giggly.Plot.geom_ribbon/3, Giggly.Plot.geom_area/3, which aligns its groups as stat_align() does, Giggly.Plot.geom_smooth/3, which fits with stat_smooth(), and Giggly.Plot.geom_density/3, which estimates with stat_density(); Giggly.Plot.annotate/3 adds one drawn from values given in the call. Every other geom, giving a stat a geom by name, layer() and ggproto() are not in Giggly yet.