I want to add an annotation outside the plotting area in a faceted ggplot. I can get the annotation that I want, but it\'s repeated for each facet. How can I get this annota
Alternatively, the package cowplot has the handy annotation function draw_label()
. When used in combination with ggdraw()
, can annotate anywhere on the canvas/sheet with the coordinates ranging from 0 to 1 (relative to the entire canvas). The function cowplot::draw_label()
uses ggplot2::annotation_custom()
under the hood.
library(ggplot2)
library(cowplot)
#> Warning: package 'cowplot' was built under R version 3.5.2
#>
#> Attaching package: 'cowplot'
#> The following object is masked from 'package:ggplot2':
#>
#> ggsave
# Revert to default theme; see https://stackoverflow.com/a/41096936/5193830
theme_set(theme_grey())
p <- ggplot(mtcars, aes(x = hp, y = mpg)) +
geom_point() +
facet_grid(. ~ cyl)
ggdraw(p) + draw_label("XX", x = 0.02, y = 0.97)
Created on 2019-01-14 by the reprex package (v0.2.1)