Skip to content

geom_text only in the first panel with facet_wrap in ggplot2

1 message · Ron Crump

#
Dear Maria,
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:

library(ggplot2)
# 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,
Ron.