Reputation: 23134
It's reasonable to set the plot region just around the data points, and not requiring the two meet at the origin, but sometimes it's desirable to have exactly that.
I am trying to achieve that with the grid package but not getting what I want:
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)
How can this be done in both the grid system and the tranditional R graphics system?
Upvotes: 1
Views: 735
Reputation: 77116
I think your problem comes from the extension argument in 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)
In base graphics,
plot(1:10, 1:10, xaxs="i", yaxs="i", xlim=c(0,10), ylim=c(0,10))
Upvotes: 1