geom_annotation.Rd
geom_annotation
geom_annotation(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
xmin = 0,
xmax = 0.5,
ymin = 0,
ymax = 0.5,
just = c(0, 0),
...,
na.rm = FALSE,
show.legend = NA,
inherit.aes = FALSE
)
Set of aesthetic mappings created by 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.
A tibble with the column of grob
The statistical transformation to use on the data for this
layer, either as a ggproto
Geom
subclass or as a string naming the
stat stripped of the stat_
prefix (e.g. "count"
rather than
"stat_count"
)
Position adjustment, either as a string naming the adjustment
(e.g. "jitter"
to use position_jitter
), or the result of a call to a
position adjustment function. Use the latter if you need to change the
settings of the adjustment.
x location (in data coordinates) giving horizontal location of raster
y location (in data coordinates) giving vertical location of raster
A string or numeric
vector specifying the justification of the viewport
relative to its (x, y) location. If there are two values, the first
value specifies horizontal justification and the second value specifies
vertical justification. Possible string values are: "left"
,
"right"
, "centre"
, "center"
, "bottom"
,
and "top"
. For numeric values, 0 means left alignment
and 1 means right alignment.
Other arguments passed on to layer()
. These are
often aesthetics, used to set an aesthetic to a fixed value, like
colour = "red"
or size = 3
. They may also be parameters
to the paired geom/stat.
If FALSE
, the default, missing values are removed with
a warning. If TRUE
, missing values are silently removed.
logical. Should this layer be included in the legends?
NA
, the default, includes if any aesthetics are mapped.
FALSE
never includes, and TRUE
always includes.
It can also be a named logical vector to finely select the aesthetics to
display.
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()
.
## make plot
library(ggplot2)
d <- data.frame(x = 1:3, y = 1:3,
varname = c("T_min", "T_max", "T_avg"))
p = ggplot(d, aes(x, y)) +
geom_point() +
geom_richtext(aes(label = varname), x = 2, y = 2) +
facet_wrap(~varname, labeller = label_mk) +
theme(
strip.text = element_markdown(face = "bold", margin = margin(t = 1, b = 0))
)
## make legend
brks = 1:5 %>% c(-Inf, ., Inf)
nbrk <- length(brks) - 1
cols <- rcolors::get_color("amwg256", nbrk)
g = make_colorbar(brks, col = cols, space = "right")
d_lgd = tibble(varname = d$varname, grob = rep(list(g), 3))
## add legend to each panel
p2 = p + geom_annotation(data = d_lgd, aes(grob = grob), xmin = 0.8, xmax = 1, ymax = 1)
p2