轉載自博客廬州月光,向作者表示感謝
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的部分
figure region width=device region width - left outer margin - right outer margin
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
plot region width= figure region width - left outer margin - right outer margin
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
通過上面幾個參數的值,對於基本繪圖系統中邊框的理解就更加清楚了。