qed
qed

Reputation: 23134

Force x-axis and y-axis to meet at (0, 0) in R

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)

enter image description here

How can this be done in both the grid system and the tranditional R graphics system?

Upvotes: 1

Views: 735

Answers (1)

baptiste
baptiste

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

Related Questions