[R] geom_text only in the first panel with facet_wrap in ggplot2

Ron Crump r@e@crump @end|ng |rom w@rw|ck@@c@uk
Mon Jun 25 13:49:18 CEST 2018

Dear Maria,

> I am trying to add text only in the first panel of a faceted ggplot
The following might help you to achieve what you
want. I created a small dummy dataset, but I tried to use
your column names in the hope this would help:

# data.frame
DF <- data.frame(Q = rep(1:5, times=2),
                  fit = rep(1:5, times=2),
                  asb_1 = rep(letters[1:2], each=5))
# a DF holding the text and where to put it
tDF<-data.frame(Q = 2, fit = 3, str = 'example', asb_1 = "a")
# basic plot
p <- ggplot(DF, aes(x = Q, y = fit)) +
        geom_point() +
        facet_wrap(~ asb_1)
# and adding the text
p <- p + geom_text(data = tDF, mapping = aes(label = str) )

Hope this is useful,

More information about the R-help mailing list