Closed kendonB closed 6 years ago
Improved annotation support will have to happen in ggplot2 directly. Any alternative has to be hackish, for technical reasons. Therefore, I'm going to close this issue.
However, for your particular problem, note that you can annotate the output from plot_grid()
, since it uses ggdraw()
internally. This may be a simpler solution.
library(ggplot2)
library(cowplot)
p <- ggplot(mpg, aes(displ, hwy)) +
geom_point()
p1 <- p
p2 <- p +
theme(axis.title.x = element_blank())
plot_grid(p1, p2, nrow = 1, align = "h") +
draw_label("Annotation\nhere", x = 0.25, y = 0.7, size = 20, hjust = 0) +
draw_label("Annotation\nhere", x = 0.75, y = 0.7, size = 20, hjust = 0)
draw_label
currently requires the user to use ggdraw before annotating a plot, which seems to mess up desirable features like alignment of plots in aplot_grid
call.Could an
annotate_label()
function implement something like this answer on SO?Examples: We can currently do this in cowplot but the axes don't align as they normally do:
The SO solution almost gets there but the postitioning seems to set the right of the annotation object instead of the left of the annotation object like
draw_label
does.Created on 2018-07-12 by the reprex package (v0.2.0.9000).