scale_x_piece() and scale_y_piece() are wrappers
around ggplot2::scale_x_continuous() and
ggplot2::scale_y_continuous() with "better"
defaults for board game diagrams.
label_letter() labels breaks with letters
and label_counting() labels breaks with positive integers
to more easily generate (i.e. chess) algebraic notation coordinates.
breaks_counting() generates breaks of just the positive integers within the limits.
Usage
scale_x_piece(
...,
name = NULL,
breaks = breaks_counting(),
minor_breaks = NULL,
labels = label_letter()
)
scale_y_piece(
...,
name = NULL,
breaks = breaks_counting(),
minor_breaks = NULL,
labels = label_counting()
)
label_letter()
label_counting()
breaks_counting()Arguments
- ...
Passed to
ggplot2::scale_x_continuous()orggplot2::scale_y_continuous().- name
The name of the scale. Used as the axis or legend title. If
waiver(), the default, the name of the scale is taken from the first mapping used for that aesthetic. IfNULL, the legend title will be omitted.- breaks
One of:
NULLfor no breakswaiver()for the default breaks computed by the transformation objectA numeric vector of positions
A function that takes the limits as input and returns breaks as output (e.g., a function returned by
scales::extended_breaks()). Note that for position scales, limits are provided after scale expansion. Also accepts rlang lambda function notation.
- minor_breaks
One of:
NULLfor no minor breakswaiver()for the default breaks (none for discrete, one minor break between each major break for continuous)A numeric vector of positions
A function that given the limits returns a vector of minor breaks. Also accepts rlang lambda function notation. When the function has two arguments, it will be given the limits and major break positions.
- labels
One of the options below. Please note that when
labelsis a vector, it is highly recommended to also set thebreaksargument as a vector to protect against unintended mismatches.NULLfor no labelswaiver()for the default labels computed by the transformation objectA character vector giving labels (must be same length as
breaks)An expression vector (must be the same length as breaks). See ?plotmath for details.
A function that takes the breaks as input and returns labels as output. Also accepts rlang lambda function notation.
Value
scale_x_piece() and scale_y_piece() return ggplot2 scale objects.
label_letter() and label_counting() return functions suitable for use with the labels scale argument.
breaks_counting() returns a function suitable for use with the breaks scale argument.
Examples
if (require("ggplot2", quietly = TRUE) && require("tibble", quietly = TRUE)) {
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_back", suit = 6, rank = 1,
x = rep(1:8, 2), y = rep(1:2, each=8))
df_b <- tibble(piece_side = "bit_back", 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() +
scale_x_piece() +
scale_y_piece() +
theme_minimal(28) +
theme(panel.grid = element_blank())
}