7

How to annotate some text in the blank space within a odd numbered faceted ggplot. Lets have a faceted ggplot with data as below with with 2 rows and 2 columns. So there is blank space in place of 2 row, 2nd column.

  df<- data.frame(Ara = rep("XTX", each = 3),
              Len = c(744, 750, 755),
              Mon = c("Sep", "Oct","Nov"),
              Value=c(11.224,10.15,4.23))
  df
  facetplot<-ggplot(df, aes(x=Value, y=Len, shape=Ara))+
      geom_point(size=5.0)+
      theme(legend.position = c(.7, .4), legend.direction="vertical")+
      facet_wrap(~Mon,scales="free_x", nrow=2)
  facetplot

enter image description here Now i am trying to annotate some text in the space but could not ( as written in red in the image). I am looking for something similar to legend.position for annotated text. Do anyone has any idea on this.Or what would be the possible work around. Thank you.

eipi10
  • 91,525
  • 24
  • 209
  • 285
Cirrus
  • 638
  • 3
  • 13
  • 26
  • Here's a [similar question](http://stackoverflow.com/questions/10014187/displaying-text-below-the-plot-generated-by-ggplot2). – S Das Apr 12 '15 at 21:18

2 Answers2

12

After you create your plot, simply use

print(facetplot)
grid.text("your text", x = 0.75, y = 0.25)

See ?grid.text for details on positioning. The default coordinate system is the entire screen device with (0,0) as the lower left and (1,1) as the upper right.

Bryan Hanson
  • 6,055
  • 4
  • 41
  • 78
  • Thank you for answering the question. I tried what you suggested but it gives an error " Error: Don't know how to add o to a plot". Any suggestions to fix this. – Cirrus Apr 12 '15 at 21:11
  • After you do `print(facetplot)` from the command line do the `grid.text` command. It's a totally separate step. – Bryan Hanson Apr 12 '15 at 21:34
  • great stuff, had faffed with annotate for a while there – Sam Apr 13 '16 at 09:06
1

To modify the graphical parameter setting for grid.text such as font color, family, fontface and size ...

grid.text("your text", x = 0.6, y = 0.15, gp = gpar(col="red", fontsize = 20, family = "Times", fontface = "italic"))
Antex
  • 1,364
  • 4
  • 18
  • 35