# NOT RUN {
p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()
# Works as ggplot2::annotate()
p + annotate("text", x = 5, y = 32, label = "Some text")
p + annotate("label", x = c(2, 5), y = c(15, 32),
label = c("A", "B"))
p + annotate("table", x = 5, y = 30,
label = data.frame(A = 1:2, B = letters[1:2]))
p + annotate("plot", x = 5.5, y = 34,
label = p + theme_bw(9))
p + annotate("rect", xmin = 3, xmax = 4.2, ymin = 12, ymax = 21, alpha = .2)
p + annotate("segment", x = 2.5, xend = 4, y = 15, yend = 25, colour = "blue")
p + annotate("pointrange", x = 3.5, y = 20, ymin = 12, ymax = 28,
colour = "red", size = 1.5)
# But ggpmisc::annotate() also works with npcx and npcy pseudo-aesthetics
p + annotate("label_npc", npcx = c(0.1, 0.9), npcy = c(0.1, 0.9),
label = c("A", "B"))
p + annotate("label_npc", npcx = 0.9, npcy = c(0.1, 0.9),
label = c("A", "B"))
p + annotate("text_npc", npcx = 0.9, npcy = 0.9, label = "Some text")
p + annotate("text_npc", npcx = "right", npcy = "top", label = "Some text")
p + annotate("table_npc", npcx = 0.9, npcy = 0.9,
label = data.frame(A = 1:2, B = letters[1:2]))
p + annotate("plot_npc", npcx = 1, npcy = 1,
label = p + theme_bw(9))
p + annotate("plot_npc", npcx = c(0, 1), npcy = c(0, 1),
label = list(p + theme_bw(9), p + theme_grey(9)),
vp.width = 0.3, vp.height = 0.4)
# }
Run the code above in your browser using DataLab