R:plot:在一个 A4 pdf 页面上正确拟合多个图 [英] R:plot : fitting multiple plots properly on one A4 pdf page

查看:38
本文介绍了R:plot:在一个 A4 pdf 页面上正确拟合多个图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多图,我想将它打印在 A4 pdf 页面上,以便图表填满整个页面.当我使用下面的代码时,图表上方和下方有很多空白空间.如何将这个空白空间减少到大约 1cm 并增加图表高度?感谢您的帮助.

I have a multiple plot and I want to print it on an A4 pdf page so that the charts fill the whole page. When I used the code below I got a lot of blank space above and below the charts. How can I reduce this blank space to about 1cm and increase the chart height? Thank you for your help.

group <- "Title"
layout(matrix(c(1:12), 6, 2) )
par(mar = c(0, 4.1, 1.5, 2.1),oma = c(2, 0, 2, 0)) 
plot(1:10)
plot(1:10)
plot(1:10)
plot(1:10)
plot(1:10)
plot(1:10)
plot(1:10)
plot(1:10)
plot(1:10)
plot(1:10)
plot(1:10)
plot(1:10)

mtext(group, outer = TRUE, cex = 1.5)
mtext("text", outer = TRUE,side =1)
dev.print(pdf, file="charts12.pdf" ,onefile=T,paper='A4') 

推荐答案

dev.print 将当前设备的图形内容复制到新设备上"(来自 ?dev.pront) 这意味着输出图形的比例取决于源设备的缩放方式.调整绘图窗口的大小会影响您获得的空白数量.

dev.print "copies the graphics contents of the current device to a new device" (from ?dev.pront) which means that the proportions of the output graphic depends on how the source device has been scaled. Resizing the plot window affects the amount of whitespace you get.

如果您另外指定widthheight,您可以将绘图适合A4,使结果独立于绘图窗口.

If you additionally specify width and height you can fit the plot to A4, making the result independent of the plot window.

dev.print(pdf, file="charts12.pdf" ,onefile=T,paper='A4', width = 21/2.54, height = 29.7/2.54) 

我将 widthheight 除以 2.54,将厘米转换为英寸.

I divided width and height by 2.54 to convert the centimeter to inches.

在@amwill04 的回答中使用 pdf()dev.off() 也可以使用,但缺点是您看不到 em> 写入文件之前的绘图.虽然这对于生产代码来说无关紧要,但它可能会使编写生成图形的代码更容易,因为只需 source 编写代码即可生成图形的预览.

Using pdf() and dev.off() as in the answer by @amwill04 also works but has the disadvantage that you do not see the plot before it is written to the file. While this should not matter with production code it may make writing the code that produces the graph easier because simply sourceing the code produces a preview of the graph.

这篇关于R:plot:在一个 A4 pdf 页面上正确拟合多个图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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