Giggly keeps the village plots: the giggly package, a grammar-of-graphics plotting
library for Elixir, modelled on R's ggplot2.
What Giggly does
The plots are on the sunny side of the village, with a shed full of string and labels. Bring Giggly a table of numbers and it gives back plot, laid out the way ggplot2 lays one out:
- Data is anything that implements Table.Reader.
- A mapping says which column goes along, which goes up and which picks the colour, like a seed packet assigned to a bed.
- Layers are planted one over another: points, lines, paths, steps, areas, ribbons, bars, histograms, densities, dotplots, boxplots, violins, tiles, contours, polygons, smooths, quantile lines, text and labels.
- Scales train each mapping to the data: continuous, log, square root, reversed, dated and discrete, with ggplot2's hues, gradients, greys and other palettes.
- Facets fence the plot into panels, one for each value of a column, or a grid of two.
- Themes are ggplot2's own: gray, bw, classic, minimal, light, dark, linedraw and void.
Giggly draws SVG for a LiveBook, a LiveView or a static page like this one. Optionally Giggly can ask his friend Pica to measure every label using the right font metrics. Pica's page shows a chart set that way.
Giggly has a few more friends now, each a package of its own. kino_giggly draws plots in Livebook. gig_typst sets titles and labels in Typst, maths included. gig_ridges draws ridgeline plots, and it's the first plugin, built on the same layer API anyone can use.
The API
Giggly.Plot builds a plot specification. Giggly uses that specification to calculate the attributes of the
plots elements and their layout, and then draw the plot.
alias Giggly.Plot
GigDatasets.mpg()
|> Plot.new(%{x: :displ, y: :hwy})
|> Plot.geom_point(%{color: :drv})
|> Plot.geom_smooth(method: :lm)
|> Plot.facet_wrap(:year)
|> Plot.labs(
x: "Engine displacement (litres)",
y: "Highway miles per gallon",
color: "Drive"
)
|> Giggly.to_svg(width: 480, height: 320)
Giggly.Plot.new/2takes the data and the plot's mapping.geom_*andstat_*add layers;scale_*,lims/2andguides/2set the scales and legends;facet_wrap/3andfacet_grid/3split the panels;labs/2names things; andtheme_*andtheme/2dress the plot.Giggly.to_svg/2draws the plot.- ggplot2's example datasets, like
mtcars,diamonds,economicsandtxhousing, are in their own package,gig_datasets, asGigDatasets.mtcars()and so on.