geom_piece() creates a ggplot2 geom. aes_piece() takes a data frame and generates an appropriate ggplot2::aes() mapping.

  mapping = NULL,
  data = NULL,
  stat = "identity",
  position = "identity",
  envir = getOption("piecepackr.envir", piecepackr::game_systems()),
  op_scale = getOption("piecepackr.op_scale", 0),
  op_angle = getOption("piecepackr.op_angle", 45),
  inherit.aes = TRUE




Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.


The data to be displayed in this layer. There are three options:

If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot().

A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify() for which variables will be created.

A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data. A function can be created from a formula (e.g. ~ head(.x, 10)).


The statistical transformation to use on the data for this layer, as a string.


Position adjustment, either as a string, or the result of a call to a position adjustment function.


Aesthetics, used to set an aesthetic to a fixed value.


Environment (or named list) containing configuration list(s).


How much to scale the depth of the piece in the oblique projection (viewed from the top of the board). 0 (the default) leads to an “orthographic” projection, 0.5 is the most common scale used in the “cabinet” projection, and 1.0 is the scale used in the “cavalier” projection.


What is the angle of the oblique projection? Has no effect if op_scale is 0.


If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders().


A data frame of game piece information with (at least) the named columns “piece_side”, “x”, and “y”.


geom_piece() requires a fixed scale coordinate system with an aspect ratio of 1 as provided by ggplot2::coord_fixed(). geom_piece() also requires that cfg is a character vector (and not a pp_cfg() object). In particular if using op_transform() one should set its argument cfg_class = "character" if intending for use with geom_piece().


geom_piece() understands the following aesthetics (required aesthetics are in bold). See pieceGrob() for more details.

  • x

  • y

  • z

  • piece_side

  • rank

  • suit

  • cfg

  • width

  • height

  • depth

  • angle

  • scale

  • type

See also

geom_piece() is a wrapper around pieceGrob().


if (require("ggplot2") && require("tibble")) { envir <- game_systems("sans") df_board <- tibble(piece_side = "board_face", suit = 3, rank = 8, x = 4.5, y = 4.5) df_w <- tibble(piece_side = "bit_face", suit = 6, rank = 1, x = rep(1:8, 2), y = rep(1:2, each=8)) df_b <- tibble(piece_side = "bit_face", suit = 1, rank = 1, x = rep(1:8, 2), y = rep(7:8, each=8)) df <- rbind(df_board, df_w, df_b) # `cfg` must be a character vector for `geom_piece()` ggplot(df, aes_piece(df)) + geom_piece(cfg = "checkers1", envir = envir) + coord_fixed() + theme_void() }
#> Loading required package: ggplot2
#> Loading required package: tibble