geom_rectmargin {ggh4x} | R Documentation |
Rectangular rugs in the margins
Description
Like rug plots display data points of a 2D plot as lines in the margins, this function plots rectangles in the margins. Rectangular rugs are convenient for displaying one-dimensional, ranged annotations for two-dimensional plots.
Usage
geom_rectmargin(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
outside = FALSE,
sides = "bl",
length = unit(0.03, "npc"),
linejoin = "mitre",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
geom_tilemargin(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
outside = FALSE,
sides = "bl",
length = unit(0.03, "npc"),
linejoin = "mitre",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
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 |
outside |
|
sides |
A |
length |
A |
linejoin |
Line join style (round, mitre, bevel). |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
Details
By default, scales are expanded 5\
whereas the rug rectangles will occupy 3\
default. The geom_rectmargin()
and geom_tilemargin()
versions do the
same thing, but are parametrised differently; see
geom_rect()
.
These functions do not have hard-coded required aesthetics, since the x and y directions can be omitted by not choosing a side in the corresponding direction, i.e. y-direction variables are omitted when plotting the rug only on the top and/or bottom. This can result in errors when the aesthetics are not specified appropriately, so some caution is advised.
Value
A Layer ggproto object.
Aesthetics
geom_rectmargin()
requires either one of the following
sets of aesthetics, but also can use both:
-
xmin
-
xmax
and/or:
-
ymin
-
ymax
geom_tilemargin()
requires either one of the following
sets of aesthetics, but can also use both:
-
x
-
width
and/or:
-
y
-
height
Furthermore, geom_rectmargin()
and geom_tilemargin()
also
understand these shared aesthetics:
alpha
colour
fill
group
linetype
size
See Also
ggplot2::geom_rug()
, geom_rect()
,
ggplot2::geom_tile()
Examples
# geom_rectmargin() is parameterised by the four corners
df <- data.frame(
xmin = c(1, 5),
xmax = c(2, 7),
ymin = c(1, 2),
ymax = c(2, 4),
fill = c("A", "B")
)
ggplot(df, aes(xmin = xmin, xmax = xmax,
ymin = ymin, ymax = ymax,
fill = fill)) +
geom_rect() +
geom_rectmargin()
# geom_tilemargin() is parameterised by center and size
df <- data.frame(
x = c(1, 4),
y = c(1, 2),
width = c(2, 1),
height = c(1, 2),
fill = c("A", "B")
)
ggplot(df, aes(x, y,
width = width, height = height,
fill = fill)) +
geom_tile() +
geom_tilemargin()