geom_box {ggh4x} | R Documentation |
Flexible rectangles
Description
The geom_box()
function offers a more flexible variant of geom_rect()
and
geom_tile()
. Instead of exclusively working with the (x/y)min
/(x/y)max
or (x/y)
/(width/height)
aesthetics, any two out of these four
aesthetics suffice to define a rectangle.
Usage
geom_box(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
linejoin = "mitre",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
radius = NULL
)
Arguments
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this
layer, either as a |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
... |
Other arguments passed on to |
linejoin |
Line join style (round, mitre, bevel). |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
radius |
A |
Value
A ggplot2 Layer
object that can be added to a plot.
Examples
# Combine any two position aesthetics
df <- data.frame(
x = c(1.5, 3.5), xmin = c(1, 2),
y = c(1.5, 2.5), ymin = c(1, 2)
)
ggplot(df) +
geom_box(aes(x = x, xmin = xmin, y = y, ymin = ymin))
# Works with partial information for position, as long as two aesthetics
# are complete for any observation.
df <- data.frame(
x = c(1.5, NA, 4), xmin = c(1, 2, NA), width = c(NA, 3, 2),
y = c(1.5, 2.5, NA), ymin = c(NA, 2, 3), height = c(1, NA, 3)
)
ggplot(df) +
geom_box(aes(x = x, xmin = xmin, y = y, ymin = ymin,
width = width, height = height))
# Set radius for rounded corners
ggplot() +
geom_box(
aes(x = 1:3, width = rep(1, 3),
y = 1:3, height = 3:1),
radius = 5
)