4

我需要在页面极端边框的 PDF 设备上书写。有了这个片段:

pdf('foo.pdf')          #Write next plot to foo.pdf in current dire 
par(mar=c(0, 0, 0, 0))  #Set numbers of lateral blank lines to zero
par(xaxs='i', yaxs='i') #Does not extend axes by 4 percent for pretty labels 
plot.new()              #Create a blank plot, as we just want to write our text  
text(0, .5, "hello", pos=4, offset=0) #Write to the right with no default 0.5 offset
dev.off()               #Close device, that is saving for a PDF device

正如预期的那样,我在页面中间的最左边得到一个foo.pdfwith hello,即:

在此处输入图像描述

不幸的是,如果我将纸张输出设置为paper='a4',那就是:

pdf('foo.pdf', paper='a4') #note the A4 setting 
par(mar=c(0, 0, 0, 0))
par(xaxs='i', yaxs='i' )
plot.new()
text(0, .5, "hello", pos=4, offset=0)
dev.off()

hello不再放在边界上,但是:

在此处输入图像描述

4

2 回答 2

2

paper设置为 以外的其他值时"special",参数pagecentre变得相关。如果将其设置为FALSE,则偏移量消失。

pdf('foo.pdf', paper='a4', pagecentre=FALSE)
par(mar=c(0, 0, 0, 0))
par(xaxs='i', yaxs='i' )
plot.new()
text(0, .5, "hello", pos=4, offset=0)
dev.off()
于 2013-10-04T09:59:37.143 回答
1

好吧,我可以确认它对我也不起作用;它看起来像一个错误恕我直言。

您的问题的解决方法是直接在pdf调用中设置 A4 纸张尺寸:

pdf('foo.pdf', width=8.3, height=11.7) #we set A4 dimensions of 8.3 x 11.7 inches
par(mar=c(0, 0, 0, 0))
par(xaxs='i', yaxs='i' )
plot.new()
text(0, .5, "hello", pos=4, offset=0)
dev.off()
于 2013-10-04T00:19:20.513 回答