View source: R/geom_annotation.R
geom_annotation | R Documentation |
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
)
mapping |
Set of aesthetic mappings created by |
data |
A tibble with the column of |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
xmin , xmax |
x location (in data coordinates) giving horizontal location of raster |
ymin , ymax |
y location (in data coordinates) giving vertical location of raster |
just |
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: |
... |
Other arguments passed on to
|
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
## 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.