添加脚注引用绘图区以外的R' [英] Add a footnote citation outside of plot area in R?

查看:235
本文介绍了添加脚注引用绘图区以外的R'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想引用注脚添加到R.制作我的3个面板面网格划分它获得信贷数据源的一个注脚。我想最好想拥有它下面和外部所有三个轴--- preferably左下角。

我用 GGPLOT2 ggsave()。这意味着我不能使用 grid.text()基于解决方案,因为只有借鉴了 X11()窗口,并且不能被添加到ggplot对象。

而不是使用 PNG()... code ... dev.off()不会出现,因为我需要一个选项 ggsave 的调整参数,并找到该命令产生更好的,更清晰的照片(同时也是快得多,因为我不打印到屏幕)。

下面是我的基本code:

  P1<  -  ggplot(数据,AES(日期值))
    facet_grid(可变〜)+ geom_point(AES(Y =值),大小= 1)+
    theme_bw()+
        OPTS(标题= mytitle)
打印(P1)
ggsave(FILE.pngWIDTH = mywidth,身高= myheight,P1,DPI = 90)

我试过:

  P1<  -  ggplot(数据,AES(日期值))
    facet_grid(可变〜)+ geom_point(AES(Y =值),大小= 1)+
    theme_bw()+
        OPTS(标题= mytitle)
打印(P1)
grid.text(单元(0.1人大),0.025,标签=的数据我礼貌)
grid.gedit(GRID.text,GP = gpar(字体大小= 7))
ggsave(FILE.pngWIDTH = mywidth,身高= myheight,P1,DPI = 90)

这适当放入左下角脚注中的X11()显示,外部的情节,但不幸的是,因为它没有应用到P1的对象,它不是由ggsave命令保存。

我也试过:

  P1<  -  ggplot(数据,AES(日期值))
    facet_grid(可变〜)+ geom_point(AES(Y =值),大小= 1)+
    theme_bw()+
    OPTS(标题= mytitle)+
注释(文本,标记=脚注中,x = 0,Y = 10,尺寸= 5,颜色=黑色)+
打印(P1)
ggsave(FILE.pngWIDTH = mywidth,身高= myheight,P1,DPI = 90)

此成功打印使用ggsave,但它存在以下的问题:


  • 据重复3次,在每个3小面的,而不是一次。

  • 这是包含在地块内,而不是外部给他们。

  • 文本难以到位---好像是用情节单元(我x轴是最新的,因此0所说的那样在1970年左右)。

  • 文本大小似乎并不尽管我的尺寸参数更改。

这时候我探讨过这个......一对夫妇的相关链接


  • GGPLOT2脚注

    (不ggsave工作)


  • <一个href=\"http://stackoverflow.com/questions/5964193/how-to-label-the-barplot-in-ggplot-with-the-labels-in-another-test-result\">How来标记barplot在与另一个测试结果的标签ggplot?

    (是小区里面,不是外在/下方图)


  • <一个href=\"http://stackoverflow.com/questions/6653193/different-font-faces-and-sizes-within-label-text-entries-in-ggplot2\">Different字体外观和大小的标​​签文本条目内GGPLOT2

    (不ggsave工作)


  • 问题保存的PDF文件中的R与GGPLOT2



解决方案

 库(gridExtra)
库(网格)
库(GGPLOT2)
G&LT; - arrangeGrob(qplot(1:10,1:10),
                 底= textGrob(从N个数据中,x = 0,
                                   hjust = -0.1,vjust = 0.1,
                                   GP = gpar(fontface =斜体
                                             字号= 18)))
ggsave(plot.pdfG)

I'd like to add a footnote citation to my 3-panel facet grid plot produced in R. It's a footnote to credit the data source. I'd ideally like to have it below and external to all three axes---preferably in the lower left.

I'm using ggplot2 and also ggsave(). This means I can't use grid.text()-based solutions, because that only draws on the x11() window, and can't be added to the ggplot object.

Using instead png() ...code... dev.off() does not appear to be an option because I need ggsave's resizing parameters, and find this command produces better, clearer prints (that are also much faster, because I'm not printing to the screen).

Here's my basic code:

p1 <- ggplot(data, aes(date, value))
    facet_grid(variable ~ .) + geom_point(aes(y =value), size=1) + 
    theme_bw() +
        opts(title=mytitle)
print(p1)
ggsave("FILE.png",width=mywidth, height=myheight, p1, dpi=90)

I've tried:

p1 <- ggplot(data, aes(date, value))
    facet_grid(variable ~ .) + geom_point(aes(y =value), size=1) + 
    theme_bw() +
        opts(title=mytitle)
print(p1)
grid.text(unit(0.1,"npc"),0.025,label = "Data courtesy of Me")
grid.gedit("GRID.text", gp=gpar(fontsize=7))
ggsave("FILE.png",width=mywidth, height=myheight, p1, dpi=90)

This appropriately puts the footnote in the lower left corner on the x11() display, external to the plots, but unfortunately, since it isn't applied to the p1 object, it isn't saved by the ggsave command.

I've also tried:

p1 <- ggplot(data, aes(date, value))
    facet_grid(variable ~ .) + geom_point(aes(y =value), size=1) + 
    theme_bw() +
    opts(title=mytitle) +
annotate("text", label = "Footnote", x = 0, y = 10, size = 5, colour = "black") +
print(p1)
ggsave("FILE.png",width=mywidth, height=myheight, p1, dpi=90)

This successfully prints using ggsave, however it has the following problems:

  • It is repeated 3 times, in each of the 3 facets, rather than 1 time.
  • It is contained within the plots, rather than external to them.
  • Text is difficult to place---seems to be using plot units (my x-axis is date, so 0 puts it around 1970).
  • The text size doesn't seem to change despite my size parameter.

A couple of related links from when I explored this...

解决方案

library(gridExtra)
library(grid)
library(ggplot2)
g <- arrangeGrob(qplot(1:10, 1:10), 
                 bottom = textGrob("data from N", x = 0, 
                                   hjust = -0.1, vjust=0.1,
                                   gp = gpar(fontface = "italic", 
                                             fontsize = 18)))
ggsave("plot.pdf", g)

这篇关于添加脚注引用绘图区以外的R'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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