coord_brick {ggbrick}R Documentation

Cartesian coordinates with fixed "aspect ratio"

Description

A fixed scale coordinate system forces a specified ratio similar to coord_fixed. It holds the coordinates fixed at the right ratio to ensure each brick is of the right dimensions.

Usage

coord_brick(
  bricks_per_layer = 4,
  ratio = NULL,
  xlim = NULL,
  ylim = NULL,
  expand = TRUE,
  clip = "on",
  width = 0.9
)

coord_waffle(
  bricks_per_layer = 4,
  ratio = NULL,
  xlim = NULL,
  ylim = NULL,
  expand = TRUE,
  clip = "on",
  width = 0.9
)

Arguments

bricks_per_layer

Number of bricks per layer. Should match the bricks_per_layer specification in geom_brick. Default is 4.

ratio

aspect ratio, expressed as y / x

xlim, ylim

Limits for the x and y axes.

expand

If TRUE, the default, adds a small expansion factor to the limits to ensure that data and axes don't overlap. If FALSE, limits are taken exactly from the data or xlim/ylim.

clip

Should drawing be clipped to the extent of the plot panel? A setting of "on" (the default) means yes, and a setting of "off" means no. In most cases, the default of "on" should not be changed, as setting clip = "off" can cause unexpected results. It allows drawing of data points anywhere on the plot, including in the plot margins.

width

Column width. If using a different width in geom_brick use the same width here to ensure correct scaling.

Value

ggplot object

Examples

# ensures that the ranges of axes are equal to the specified ratio by

library(ggplot2)
library(dplyr)

# create a base plot
plt <- mpg %>%
  count(class, drv) %>%
  ggplot() +
  geom_brick(aes(class, n, fill = drv), bricks_per_layer = 6)

# view the base plot
plt

# View the base plot with fixed coords
# Ensure `bricks_per_layer` matches the geom
plt %>%
  coord_brick(6)

# The same using `geom_waffle`
mpg %>%
  count(class, drv) %>%
  ggplot() +
  geom_waffle(aes(class, n, fill = drv), bricks_per_layer = 6) +
  coord_waffle(6)

[Package ggbrick version 0.3.0 Index]