2013-03-31 31 views
3

有時我正在編寫多部分圖形,而且佈局複雜,而且我想在打印機外部進行打印。 (我用比喻和字面來說)。如何在多個佈局區域進行打印

使用R基圖形功能layout()設置一個複雜的佈局考慮這個例子:

## Define the layout regions 
multiPartFigureLayout <- structure(c(4, 4, 1, 1, 2, 2, 3, 3, 8, 8, 
             5, 5, 1, 1, 2, 2, 3, 3, 8, 8, 
             9, 9, 1, 1, 2, 2, 3, 3, 8, 8, 
             6, 6, 1, 1, 2, 2, 3, 3, 8, 8, 
             7, 7, 1, 1, 2, 2, 3, 3, 8, 8), 
             .Dim = c(10L, 5L)) 

## Demonstrate the layout 
win.graph(4, 5) 
layout(multiPartFigureLayout) 
layout.show(9) 

這將產生以下繪製佈局。 (我已經添加了紅色用圖像編輯軟件文本)

enter image description here

這是禁區外繪製的一個應用:中所示的區域套印文本。同樣,可能需要疊印另一個圖形元素。例如,繪製一個跨越框的規則。

我知道有可能擴大multiPartFigureLayout矩陣並添加一個可以容納文本或規則的繪圖區域。但我不想這樣做:我想跨越多個佈局區域進行疊印。

有沒有一種方法可以使用基礎圖形來做到這一點,或者使用一個功能來達到這個目的,或者以某種方式欺騙繪圖功能?如果你使用負「行」值

+0

我想我們有不同的意思附加到「繪圖」一詞。我將點,線和曲線想象爲「繪圖」,並將傳說和文本添加爲​​「註釋」。但這是你的問題。 –

+0

我感謝你的回答@DWin,正確和有用。但我認爲我應該擴大一點,讓其他人更有用。查看我的關於繪製其他圖形元素(例如規則)的編輯。 – digitalmaps

回答

2

要畫的東西,超出了當前的情節設置par(xpd=NA)。您可以使用的功能grconvertXgrconvertY到不同的座標系之間進行轉換。

您可以通過轉換爲'ndc'座標來保存某個地點的位置,然後將其轉換爲用戶座標在另一個繪圖中可以使用這些函數來查找相對於當前繪圖,圖形或設備的座標以傳遞給其他函數。一個例子:

layout(matrix(c(1,2,3,2), 2)) 
par(xpd=NA) 
with(iris, plot(Sepal.Width, Sepal.Length, col=Species)) 
save1.x <- grconvertX(0.25, from='npc', to='ndc') 
save2.x <- grconvertX(iris$Sepal.Width[1], to='ndc') 
save2.y <- grconvertY(iris$Sepal.Length[1], to='ndc') 
with(iris, plot(Petal.Width, Petal.Length, col=Species)) 
with(iris, arrows(Petal.Width[1], Petal.Length[1], 
    grconvertX(save2.x, from='ndc'), 
    grconvertY(save2.y, from='ndc'), col='orange')) 
with(iris, plot(Petal.Length, Sepal.Length, col=Species)) 
segments(grconvertX(0.75, from='npc'), grconvertY(0.9, from='npc'), 
    grconvertX(save1.x, from='ndc'), col='purple') 
+0

使用'par(xpd = NA)'與這些鮮爲人知的功能相結合,整個設備是您的繪圖。非常好。 – digitalmaps

4
mtext("even longer test of overplotting to see if it extends across the plots" , line=-1, col="red") 
?mtext 

mtext可以註釋內部和整個圖形的區域的界限。 (mtext的參數默認爲3(=「top」)。如果您嘗試使用text,您會發現它難以延伸到區域邊界。我嘗試使用xpd=TRUE作爲參數text以獲取但未成功也許使用它與par()text通話將允許它的工作。

+0

+1非常聰明。 –