2017-02-22 17 views
5

par(fig)設置圖形參數並使用原始參數重置它們後,繪圖邊距中的文本不會寫入。 只有在之後的另一個低級別命令執行繪圖區域將執行它將再次工作。這裏有一個例子:par(fig)後,不寫入邊距文本

dev.off() 
plot(1:10) 
op <- par(no.readonly = TRUE) 
mtext("hello", adj=1, col=2)   # written as expected 
par(fig=c(0.1,0.6,0.5,0.8), new=TRUE) 
par(op) 
mtext("hello ", adj=1, col=3)   # not written 
mtext("hello ", adj=1, col=3, line=-1) # works inside plot region 
mtext("hello ", adj=1, col=3)   # still not written 
text(50,20,"") # or abline    # do something inside plot region 
mtext("hello   ", adj=1, col=3) # now it works! 

這可能涉及到另外一個問題,我張貼after par(fig), mtext is slightly off下。

除了mtextaxis也不起作用。除了text/abline/pointstitle(main="dummy")也解決了這個問題。

這可能是一個R bug?或者我錯過了什麼?

+0

我懷疑par(op)'開始一個新的情節。將'par(op)'替換爲'par(fig = op $ fig,new = TRUE)',它按預期工作。 –

+0

現在很有趣! 'par(fig = op $ fig)'沒有'new'就足夠了,順便說一下..這並不能解釋它爲什麼在繪圖區域工作,但不在邊緣,儘管...... –

回答

5

通過試驗和錯誤,它歸結爲par(mfg=c(1, 1, 1, 1))

plot(1:10) 
op <- par(no.readonly = TRUE) 
mtext("hello", adj=1, col=2)   # written as expected 
par(op[names(op) == "mfg"]) 
mtext("bye ", adj=1, col=3)   # not written 
mtext("hello ", adj=1, col=3, line=-1) # works inside plot region 

plot(1:10) 
op <- par(no.readonly = TRUE) 
mtext("hello", adj=1, col=2)   # written as expected 
par(op[names(op) != "mfg"]) 
mtext("bye ", adj=1, col=3)   # written as expected 
mtext("hello ", adj=1, col=3, line=-1) # works inside plot region 

這不是很清楚,我爲什麼設定圖下一個要繪製應停用空白打印文本(未在圖中),由於mtext是用C語言實現,這將需要一些努力工作出來。