Documentation
¶
Overview ¶
Package facet splits one chart into small multiples.
A facet takes the layers of a plot, cuts their rows by the values of a column, and hands each group its own panel. Every panel is drawn with the same geoms and — unless told otherwise — the same scales, which is the whole point: small multiples work because the only thing that varies between panels is the data.
p.Facet(facet.Wrap("region", facet.Columns(3)))
Wrap flows panels left to right and wraps; Grid crosses two columns, one down the rows and one across the columns. Either way the panels' axes are aligned by the layout solver, so a position in one panel means the same as the same position in the next.
Scales ¶
Shared by default. FreeX, FreeY and Free give each panel a scale of its own, which answers a different question — "what is the shape of this group" rather than "how do these groups compare" — and should be a deliberate choice, because a reader who does not notice the axes changed will read the panels as comparable when they are not.
Layers without data ¶
A layer that holds no rows — an annotation, a reference line — cannot be split, so it is drawn in every panel. That is what you want: a threshold applies to all of them.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoColumn = errors.New("figure/facet: column not found in any layer")
ErrNoColumn reports a facet column that none of the layers has.
Functions ¶
This section is empty.
Types ¶
type Desc ¶
type Desc struct {
// Row and Col name the columns split on. A wrapped facet leaves Row empty
// and flows its panels; a grid crosses the two.
Row, Col string
// Wrap reports a wrapped facet rather than a grid.
Wrap bool
// Columns caps how many panels a wrap puts in a row. Zero means the
// derived, roughly square default.
Columns int
// FreeX and FreeY give each panel its own axis.
FreeX, FreeY bool
}
Desc is a facet specification reduced to what configures it, so that a faceted chart can be written down and read back.
type Option ¶
type Option func(*Spec)
Option configures a facet.
type Panel ¶
type Panel struct {
// Row and Col place the panel in the grid.
Row, Col int
// Strip is the label above the panel.
Strip string
// RightStrip is the label beside it, used by [Grid] to name a row once
// rather than on every panel in it.
RightStrip string
// Layers are the plot's layers restricted to this panel's rows. Layers
// that hold no data are carried through unchanged.
Layers []geom.Geom
}
Panel is one facet: where it sits, what it is called, and the layers cut down to its rows.
type Spec ¶
type Spec struct {
// contains filtered or unexported fields
}
Spec describes how a plot is split into panels.
func FromDesc ¶
FromDesc builds the facet d describes. It returns nil for a Desc naming no column, which is how "this chart is not faceted" is written down.
func Grid ¶
Grid crosses two columns: rowCol runs down the rows, colCol across the columns. A panel exists for every combination that has rows; the rest are holes, which is itself information.
func (*Spec) FreeScales ¶
FreeScales reports whether each panel gets its own X or Y scale.