-1

I wonder how I put different text in individual facets. I want to add the text inside the plot using annotate or geom_text() I know there are duplicated posts in this, but I don't manage to get it correct. Here is my data:

Experiment         FC           Pairing
Meister et al. -2.74236520      yes
Meister et al. -0.7436354       no
Meister et al. -2.74236520      yes
Meister et al. -0.73536354      no
daub et al.    -0.64246768      yes
daub et al.    -0.6663321       no
daub et al.    -0.64246768      yes
daub et al.    -0.6663321       no
hans et al.    -2.32230716      yes
hans et al.    -0.49423279      no
hans et al.    -2.32723716      yes
hans et al.    -0.4944279       no

ggplot(combined_pos1,aes(Pairing,FC,fill=as.factor(Pairing))) + 
      geom_boxplot(fill = "grey90") +  coord_cartesian(ylim=c(-3,3)) + 
      facet_grid(~Experiment)
BioMan
  • 694
  • 11
  • 23
  • 1
    Did you try this approach http://stackoverflow.com/questions/11889625/annotating-text-on-individual-facet-in-ggplot2 – user20650 Oct 14 '14 at 22:54
  • Are you saying you want to change the text in the strip labels for each facet (where it currently says "Meister et al.", "Daub et al.", etc.), or are you saying you want to place text annotations inside the plot area of each facet? – eipi10 Oct 14 '14 at 23:22
  • 4
    Suggestion: Post your data in a reproducible form using output of `dput` – IRTFM Oct 15 '14 at 00:16
  • @eipi10 Yes I want to add the text as annotation inside the plot. One unique text for each facet. – BioMan Oct 15 '14 at 08:13

1 Answers1

4

create the annotations for each facet (here as an example for Meister and Hans):

combined_pos1$annotations = c("Text for Meister",rep("",10),"Text for hans")

include geom_text:

g = ggplot(combined_pos1,aes(Pairing,FC,fill=as.factor(Pairing))) + geom_boxplot(fill = "grey90") +  coord_cartesian(ylim=c(-3,3)) + facet_grid(~Experiment)
g = g + geom_text(aes(x=2.5,y=2.5,label=annotations))
g

This yields the following: enter image description here

Community
  • 1
  • 1
CMichael
  • 1,856
  • 16
  • 20
  • @BioMan This is a clear duplicate, the answer was given to you in the comments but you didn't read. – baptiste Oct 15 '14 at 14:40
  • 1
    @baptiste Sorry if I missed something in the comments. – CMichael Oct 15 '14 at 14:41
  • 1
    If you want to add text to multiple rows, make sure that your `colnames()` in the text `data.frame` match those of the data you are about to plot. – Kots Oct 04 '18 at 11:23