如何在文档ggplot的空白区域中定位注释文本 [英] How to position annotate text in the blank area of facet ggplot

查看:193
本文介绍了如何在文档ggplot的空白区域中定位注释文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在奇数分面ggplot内的空白空间中注释一些文本。
让我们有一个带有2行和2列数据的分面ggplot。

  df < -  data.frame(Ara = rep( XTX,每个= 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 )+
主题(legend.position = c(.7,.4),legend.direction =vertical)+
facet_wrap(〜Mon,scales =free_x,nrow = 2)
facetplot

现在我试图在空间中注释一些文本,但不能(如图中红色所示)。我正在寻找类似legend.position的注释文本。有没有人对此有任何想法。或者可能的解决方案是什么。
谢谢。

解决方案

创建图后,只需使用

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

有关定位的详细信息,请参见?grid.text 。默认坐标系是整个屏幕设备,(0,0)为左下角,(1,1)为右上角。

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

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.

解决方案

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.

这篇关于如何在文档ggplot的空白区域中定位注释文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆