0

I am attempting to add labels (capital letters) to each plot in the following facet_grid:

p <- ggplot(mpg, aes(displ, cty)) + geom_point()
p + facet_grid(drv ~ cyl)

This outputs: enter image description here

What I would like to have is this: enter image description here The major issues I am having is 1) My Y axis is scaled freely, so inputting specific coordinates for each isn't working. 2) I am not sure what keywords I should be searching here, I am sure there is a way to do this in facet_grid but I am unable to find it.

Richard Telford
  • 9,558
  • 6
  • 38
  • 51
AMB
  • 129
  • 8
  • I can give you a solution but without using facet_grid, and using instead ggpubr and creating each plot panel. I don't know if that would be useful for you. If it is, I will post it. – Santiago I. Hurtado May 24 '19 at 18:35
  • 1
    The `tag_facet` function from the `egg` package should do it https://stackoverflow.com/a/52217208/786542 – Tung May 24 '19 at 19:27
  • 1
    That is exactly what I was looking for and works nicely. Thank you! – AMB May 24 '19 at 19:52
  • @AMB: not a problem. Feel free to post an answer to help future readers – Tung May 27 '19 at 01:12

1 Answers1

1

How about this? Fixing the position of label as the upper-left corner of each plot panel:

 p + facet_grid(drv ~ cyl)+ annotate('text', label = LETTERS[1:12], x=min(mpg$displ), y=max(mpg$cty))

You can replace label =c('aaa','bb','fff'....), anything you like, but has to be the same number of your facet plots.

You can also fine-tune the position of the label proportional to both axis by using:

x=mean(mpg$displ)*0.6, y=max(mpg$cty)*0.97
maizer
  • 151
  • 3