R语言绘图边框

转载自博客庐州月光,向作者表示感谢
http://www.cnblogs.com/xudongliang/p/6888884.html

在R语言中, 绘图边框一共有3个区域:

device region :
figure region :
plot region :

在描述不同区域大小的时候,有对应的不同参数:

din : 返回device region 的宽度和高度, 单位为inches
fin : 返回figure region 的宽度和高度,单位为inches
pin : 返回plot region 的宽度和高度, 单位为inches

代码示例:

> pdf("a.pdf", height = 10, width = 10)
> par("din")
[1] 10 10
> par("fin")
[1] 10 10
> par("pin")
[1] 8.76 8.16

#首先创建一个绘图设置,这里我们创建一个宽度和高度都为10的pdf,单位是inches
#通过din参数的返回值可以看到,pdf对应的宽度和高度都是10 inches
#通过fin参数的返回值可以看到,figure region对应的宽度和高度都是10 inches
#通过pin参数的返回值可以看到,plot region 对应的宽度和高度分别是8.76 和 8.16 inches

device region 的宽度和高度很好理解,是我们在绘图时设置的, 但是figure region 和 plot region 的宽度和高度是如何得到的呢?

在device region 和 figure region 之间,存在 outer magin, 默认情况下,outer margin 4个方向的值都为0,所以 device region 和 figure region 的宽度和高度一致。我们通过设置 omi 参数的值再来看一下。

> pdf("a.pdf", height = 10, width = 10)
> par(omi = c(1, 2, 1, 2))
> par("din")
[1] 10 10
> par("fin")
[1] 6 8

我们可以看到,device region的宽度和高度都是10, 而figure reigon的宽度和高度变成了6和8, 少的就是outer margin的部分

  1. figure region width=device region width - left outer margin - right outer margin

  2. figure region height= device region heigth - top outer margin - bottom outer margin

根据上面的公式, figure region 的宽度 10 - 2 - 2 = 6, figure region 的高度 = 10 - 1 - 1 = 8

同样的道理,在figure region 和 plot region 之间存在margin

  1. plot region width= figure region width - left outer margin - right outer margin

  2. plot region height = device region heigth - top outer margin - bottom outer margin

> pdf("a.pdf", height = 10, width = 10)
> par(mai = c(1, 2, 1, 2))
> par("fin")
[1] 10 10
> par("pin")
[1] 6 8

根据上面的公式, plot region 的宽度 10 - 2 - 2 = 6, plot region 的高度 = 10 - 1 - 1 = 8

通过上面几个参数的值,对于基本绘图系统中边框的理解就更加清楚了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章