Adjust margins in persp/persp3d in R
<p>Long-time reader; first-time poster here.  I am posting because I am trying to create multi-panel 3-dimensional plots with custom axes, and I cannot seem to do it without cutting off the axis labels.</p>

<p>More specifically, I am trying to create a plot using <code>persp3D()</code> in the <code>plot3D</code> package.  It's a function that uses <code>persp()</code>.  It's easy to set <code>persp(..., axes = F)</code> to turn off the axes.  From there, like <code>persp()</code>, I can use <code>trans3d()</code> to add lines, text, etc., as shown elsewhere (for example, <a href="http://entrenchant.blogspot.co.id/2014/03/custom-tick-labels-in-r-perspective.html" rel="nofollow noreferrer">link</a>).  Adding the axes and axis labels works just fine, but I cannot figure out how to increase the margins to accommodate the axis labels I am adding to the plot.</p>

<p>Here is a reproducible example:</p>

<pre><code>par(mfrow = c(1,3))
# fake data
test.mat &lt;- matrix(runif(100)*1:10, nrow = 10)

# describe axis parameters
x.axis &lt;- seq(from = 0, to = 1, by = .1)
min.x &lt;- min(x.axis); max.x &lt;- max(x.axis)
y.axis &lt;- seq(from = 0, to = 1, by = .1)
min.y &lt;- min(y.axis); max.y &lt;- max(y.axis)
z.axis &lt;- pretty(seq(from = min(test.mat), to = max(test.mat), by = 0.1))
min.z &lt;- min(z.axis); max.z &lt;- max(z.axis)

# 3d plot without axes
pmatt &lt;- persp(test.mat, box = F, theta = 35, axes = F, xaxs = "i")

# just a little function for plotting the axes
bbox &lt;- function(min.x, max.x, min.y, max.y, min.z, max.z, pmat, ...){
    lines(trans3d(min.x, min.y, c(min.z, max.z), pmat), ...)
    lines(trans3d(min.x, max.y, c(min.z, max.z), pmat), ...)
    lines(trans3d(max.x, max.y, c(min.z, max.z), pmat), ...)
    lines(trans3d(c(min.x, max.x), max.y, max.z, pmat), ...)
    lines(trans3d(min.x, c(min.y, max.y), max.z, pmat), ...)
}

# print axes
bbox(min.x, max.x, min.y, max.y, min.z, max.z, pmat = pmatt)

# create ticks and labels, and place them with trans3d
tick.start &lt;- trans3d(x.axis, min.y, min.z, pmatt)
tick.end &lt;- trans3d(x.axis, (min.y - 0.10), min.z, pmatt)
segments(tick.start$x, tick.start$y, tick.end$x, tick.end$y)
label.pos &lt;- trans3d(x.axis[], (min.y - 0.15), min.z, pmatt)
text(label.pos$x, label.pos$y, labels = c(x.axis), adj = c(1, 0.95), srt = 0, cex = 1)

tick.start &lt;- trans3d(max.x, y.axis, min.z, pmatt)
tick.end &lt;- trans3d((max.x + 0.1), y.axis, min.z, pmatt)
segments(tick.start$x, tick.start$y, tick.end$x, tick.end$y)
label.pos &lt;- trans3d((max.x + 0.15), y.axis, min.z, pmatt)
text(label.pos$x, label.pos$y, labels = c(x.axis), adj = c(0, 0.95), srt = 0, cex = 1)

tick.start &lt;- trans3d(min.x, min.y, z.axis, pmatt)
tick.end &lt;- trans3d(min.x, (min.y - 0.1), z.axis, pmatt)
segments(tick.start$x, tick.start$y, tick.end$x, tick.end$y)
label.pos &lt;- trans3d((min.x - 0.15), min.y, z.axis[-1], pmatt)
text(label.pos$x, label.pos$y, labels = z.axis[-1], adj = c(1.5, NA), srt = 0, cex = 1)
</code></pre>

<p>And, in all, the labels are cutoff by the margin.  Any help would be greatly appreciated.</p>