Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
811 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...