Learn R Programming

ggplot2 (version 4.0.1)

Facet: Facets

Description

All facet_*() functions returns a Facet object or an object of a Facet subclass. This object describes how to assign data to different panels, how to apply positional scales and how to lay out the panels, once rendered.

Arguments

Details

Extending facets can range from the simple modifications of current facets, to very laborious rewrites with a lot of gtable() manipulation.For some examples of both, please see the extension vignette. The object and its parameters are chaperoned by the Layout class.

Facet subclasses, like other extendible ggproto classes, have a range of methods that can be modified. Some of these are required for all new subclasses, while other only need to be modified if need arises.

The required methods are:

  • compute_layout

  • map_data()

  • draw_panels() or its subsidiaries:

    • init_gtable()

    • attach_axes()

    • attach_strips()

In addition to the methods above, it can be useful to override the default behaviour of one or more of the following methods:

  • setup_params()

  • init_scales()

  • train_scale()

  • finish_data()

  • draw_back(), draw_front() or draw_labels()

All extension methods receive the content of the params field as the params argument, so the constructor function will generally put all relevant information into this field.

See Also

The the new facets section of the online ggplot2 book.

Run vignette("extending-ggplot2"), in particular the "Creating a new faceting" section.

Other Layout components: Coord, Layout

Examples

Run this code
# Please see extension vignette
NULL

Run the code above in your browser using DataLab