I have a ggplot facet_grid where I want to add different text labels to each individual plot.
I have read this for mapping to a one-dimensional facet_grid
library(ggplot2)
ann_text <- data.frame(mpg = c(14,15),wt = c(4,5),lab=c("text1","text2"),
cyl = factor(c(6,8),levels = c("4","6","8")))
p <- ggplot(mtcars, aes(mpg, wt)) +
geom_point() +
facet_grid(gear ~ cyl) +
geom_text(data = ann_text,aes(label =lab) )
But this produces the following:
How does the matching to ann_text
work inside the geom_text
?