ggplot2-ggproto: Base ggproto classes for ggplot2

Description Geoms Coordinate systems Facets Stats Positions Scales See Also

Description

If you are creating a new geom, stat, position, or scale in another package, you'll need to extend from ggplot2::Geom, ggplot2::Stat, ggplot2::Position, or ggplot2::Scale.

Geoms

All geom_* functions (like geom_point) return a layer that contains a Geom* object (like GeomPoint). The Geom* object is responsible for rendering the data in the plot.

Each of the Geom* objects is a ggproto() object, descended from the top-level Geom, and each implements various methods and fields. To create a new type of Geom object, you typically will want to implement one or more of the following:

Compared to Stat and Position, Geom is a little different because the execution of the setup and compute functions is split up. setup_data runs before position adjustments, and draw_layer is not run until render time, much later. This means there is no setup_params because it's hard to communicate the changes.

Coordinate systems

All coord_* functions (like coord_trans) return a Coord* object (like CoordTrans).

Each of the Coord* objects is a ggproto() object, descended from the top-level Coord. To create a new type of Coord object, you typically will want to implement one or more of the following:

Facets

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.

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.

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:

In addition to the methods described above, it is also possible to override the default behaviour of one or more of the following methods:

All extension methods recieve the content of the params field as the params argument, so the constructor function will generally put all relevant information into this field. The only exception is the shrink parameter which is used to determine if scales are retrained after Stat transformations has been applied.

Stats

All stat_* functions (like stat_bin) return a layer that contains a Stat* object (like StatBin). The Stat* object is responsible for rendering the data in the plot.

Each of the Stat* objects is a ggproto() object, descended from the top-level Stat, and each implements various methods and fields. To create a new type of Stat object, you typically will want to implement one or more of the following:

Positions

All position_* functions (like position_dodge) return a Position* object (like PositionDodge). The Position* object is responsible for adjusting the position of overlapping geoms.

The way that the position_* functions work is slightly different from the geom_* and stat_* functions, because a position_* function actually "instantiates" the Position* object by creating a descendant, and returns that.

Each of the Position* objects is a ggproto() object, descended from the top-level Position, and each implements the following methods:

And the following fields

Scales

All scale_* functions (like scale_x_continuous) return a Scale* object (like ScaleContinuous). The Scale* object represents a single scale.

Each of the Scale* objects is a ggproto() object, descended from the top-level Scale.

See Also

ggproto


SahaRahul/ggplot2 documentation built on May 17, 2019, 1:46 p.m.