2013-10-19 119 views
1

將繪圖區域設置在數據點的周圍並且不要求兩者在原點相遇是合理的,但有時希望具有確切的說。強制X軸和Y軸在R處的(0,0)處相遇

我想實現的是與格包,但沒有得到我想要的:

require(grid) 
grid.newpage() 
pushViewport(plotViewport(c(5, 5, 5 ,5))) 
pushViewport(dataViewport(1:10, 1:10)) 
grid.points(1:10, 1:10, default.units='native') 
grid.xaxis(at=0:10) 
grid.yaxis(at=0:10) 

enter image description here

這怎麼能在網格系統和場景下的傳統R圖形系統都做什麼?

回答

1

我覺得你的問題來自於擴展論點dataViewport

require(grid) 
grid.newpage() 
pushViewport(plotViewport(c(5, 5, 5 ,5))) 
pushViewport(dataViewport(0:10, 0:10, extension=c(0,0))) 
grid.points(1:10, 1:10, default.units='native') 
grid.xaxis(at=0:10) 
grid.yaxis(at=0:10) 

在基礎圖形,

plot(1:10, 1:10, xaxs="i", yaxs="i", xlim=c(0,10), ylim=c(0,10))