Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
612 views
in Technique[技术] by (71.8m points)

r - How to position annotate text in the blank area of facet ggplot

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.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...