geom_grob
adds a Grob as inset to the ggplot using syntax
similar to that of geom_label
.
geom_grob(mapping = NULL, data = NULL, stat = "identity",
position = "identity", ..., na.rm = FALSE, show.legend = FALSE,
inherit.aes = FALSE)geom_grob_npc(mapping = NULL, data = NULL, stat = "identity",
position = "identity", ..., na.rm = FALSE, show.legend = FALSE,
inherit.aes = FALSE)
A layer specific dataset - only needed if you want to override the plot defaults.
The statistical transformation to use on the data for this layer, as a string.
Position adjustment, either as a string, or the result of a call to a position adjustment function.
If FALSE
(the default), removes missing values with a
warning. If TRUE
silently removes missing values.
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.
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
.
You can modify table alignment with the vjust
and
hjust
aesthetics. These can either be a number between 0
(right/bottom) and 1 (top/left) or a character ("left", "middle", "right",
"bottom", "center", "top").
You can modify inset plot size with the vp.width
and vp.height
aesthetics. These can be a number between 0 (smallest
posisble inset) and 1 (whole plotting area width or height). The default
value for for both of these aesthetics is 1/3.
Note the "width" and "height" like of a text element are 0, so stacking and dodging Grobs will not work by default, and axis limits are not automatically expanded to include all inset Grobs. Obviously, Grobs do have height and width, but they are in physical units, not data units. The amount of space they occupy on the main plot is constant in data units.
The idea of implementing a geom_custom()
for grobs has
been discussed as an issue at
https://github.com/tidyverse/ggplot2/issues/1399.
# NOT RUN {
library(tibble)
df <- tibble(x = 2, y = 15, grob = list(grid::circleGrob(r = 0.2)))
ggplot(data = mtcars, aes(wt, mpg)) +
geom_point(aes(colour = factor(cyl))) +
geom_grob(data = df, aes(x, y, label = grob))
# }
Run the code above in your browser using DataLab