class_definitions: Class definitions

class_definitionsR Documentation

Class definitions

Description

The S7 object oriented programming system requires class definitions. Here, we provide definitions of classes that are home to ggplot2.

S7 classes

A general advice the S7 package gives is to name class definition objects the same as the class name, which then becomes the constructor for the class. The classes listed below deviate from that advice for historical reasons, because some constructors like ggplot() are also S3 generics with methods. The have the class_-prefix to indicate their role.

  • class_ggplot is an S7 class used for objects generated by ggplot().

  • class_ggplot_built is an S7 class used for objects generated by ggplot_build().

  • class_mapping is an S7 class used for objects generated by aes().

  • class_theme is an S7 class used for objects generated by theme().

  • class_labels is an S7 class used for objects generated by labs().

  • class_gg is an abstract S7 class to used invoke similar behaviour among ggplot objects.

Theme elements

The theme elements follow the advice of the S7 package that the class names are also the class definitions and constructors.

  • element is an abstract S7 class used to invoke similar behaviour among theme element objects.

  • element_blank is an S7 class for not drawing theme elements.

  • element_rect is an S7 class for drawing rectangles.

  • element_line is an S7 class for drawing lines.

  • element_text is an S7 class for rendering text.

  • element_polygon is an S7 class for drawing polygons.

  • element_point is an S7 class for drawing points.

  • element_geom is an S7 class holding geom defaults.

  • margin is an S7 class for declaring margins.

ggproto classes

The ggproto classes are S3 classes of the type environment that form the backbone of most systems in ggplot2 and are in particular crucial to the extension system.

  • class_ggproto is an S3 class used for the objects generated by ggproto() which are of the type environment.

  • class_scale is a subclass of class_ggproto and is more described in the Scale documentation.

  • class_guides is a subclass of class_ggproto and is considered an internal class.

  • class_guide is a subclass of class_ggproto and is more described in the Guide documentation.

  • class_coord is a subclass of class_ggproto and is more described in the Coord documentation.

  • class_facet is a subclass of class_ggproto and is more described in the Facet documentation.

  • class_layer is a subclass of class_ggproto and is used for the objects generated by layer(). The class itself is considered internal and is described in more detail in the Layer documentation.

  • class_layout is a subclass of class_ggproto and is considered an internal class. It is described in more detail in the Layout documentation.

  • class_scales_list is a subclass of class_ggproto and is considered an internal class.

S3 classes

Some simple classes remain S3, primarily because they aren't meant to be recycled into new classes.

  • [Superseded] class_S3_gg is a temporary S3 class until R 4.3.0 is the minimum supported version. It is exported and listed here for completeness, but its use is heavily discouraged. It is superseded by class_gg.

  • class_rel is an S3 class used in element properties.

  • class_zero_grob is an S3 class used to indicate empty drawings.

  • class_waiver is an S3 sentinel value class used in various places.

  • class_derive is an S3 sentinel value class used primarily in sec_axis().


ggplot2 documentation built on Sept. 11, 2025, 9:10 a.m.