Reputation: 2107
I have a small subplot just with the axes:
par(mar=c(0.1, 0.1, 1.0, 37))
plot(NULL, axes=FALSE, xlim=c(0,0), ylim=ylim.axis_right, type="n", ann=FALSE)
axis(4, at=c(ylim.axis_right[1], ylim.axis_right[1]/2, 0, ylim.axis_right[2]/2, ylim.axis_right[2]), labels=FALSE, lwd=6, col="#000000")
box()
Where ylim.axis_right is a 2-vector of form: (-x,x).
My problem is that I have provided the same ylim for both the dummy plot and axes most outside markers and I expected the actual axis to be stretched to the limits of the box. Why is it not happening and how should I correct it?
Upvotes: 0
Views: 101
Reputation: 37641
The problem is that by default, R will increase the size of the plot by 4%. You can suppress that with yaxs="I". This is explained on the help page ?par
.
xaxs
The style of axis interval calculation to be used for the x-axis. Possible values are "r", "i", "e", "s", "d". The styles are generally controlled by the range of data or xlim, if given.
Style "r" (regular) first extends the data range by 4 percent at each end and then finds an axis with pretty labels that fits within the extended range.
Style "i" (internal) just finds an axis with pretty labels that fits within the original data range.yaxs
The style of axis interval calculation to be used for the y-axis. See xaxs above.
So you can get the effect that you want by specifying yaxs="i"
par(mar=c(0.1, 0.1, 1.0, 29))
ylim.axis_right = c(-1,1)
plot(NULL, axes=FALSE, xlim=c(0,1), ylim=ylim.axis_right, type="n", ann=FALSE, yaxs="i")
axis(4, at=c(ylim.axis_right[1], ylim.axis_right[1]/2, 0, ylim.axis_right[2]/2,
ylim.axis_right[2]), labels=FALSE, lwd=6, col="#000000")
box()
Upvotes: 1