# [R] 3d plotting alternatives. I like persp, but regret the lack of plotmath.

Paul Johnson pauljohn32 at gmail.com
Thu Dec 29 19:01:13 CET 2011

```I have been making simple functions to display regressions in a new
package called "rockchalk".  For 3d illustrations, my functions use
persp, and I've grown to like working with it.  As an example of the
kind of things I like to do, you might consult my lecture on
multicollinearity, which is by far the most detailed illustration I've
prepared.

http://pj.freefaculty.org/guides/stat/Regression/Multicollinearity/Multicollinearity-1-lecture.pdf

I used persp mainly because I can understand it, and it can be made to
work like plot in R, with additional tools like lines and points and
such.  I don't want to interact with these plots, I just need to put
them into lectures & documents relatively easily.  And I've also
succeeded in turning them into flash video with R2SWF, which works
great!

Last summer, I put together some lecture notes illustrating persp,
scatterplot3d, and persp3d.
http://pj.freefaculty.org/guides/Rcourse/plot-3d/plots-3d.pdf.  As I
review that now, I see I did not make any progress on the lattice
based plotters, or I did not write it down, anyway.  scatterplot3d did
almost everything I needed to do, but not everything, and so I used

Then I put some plot math in an axis label and ran into the problem
that everybody else who uses persp finds, eventually. persp doesn't
allow expressions in axis labels.  From searching in r-help, I see
that many people have run up against the same trouble. Most people say
"too bad", I'll switch to some other tool.

Suggested alternatives.

1. Use wireframe or cloud in lattice. They can handle plotmath.

I've been studying that, and it can handle plot math, but I just can't
get the kinds of graphs I want from it.  In the persp framework, I can
draw the 3d plot, and then add details to it one by one.  I can
comprehend the little steps.  In wireframe and cloud, it *appears* to
me i have to pack all of that work into one single command, and it is,
well, either too difficult or impossible.  Or perhaps I'm just not
understanding the documentation.  If I could make the sorts of plots I
need with lattice tools, I would do it.  But I'm really blocked at the
front door by the "write one giant function call" nature of it.

I realize that's vague because I have not told you specifically what I
want to do.  If there is a lattice expert reading, can you give me
some HOWTO hints?  Take, for example, Slide 19 in this one:

http://pj.freefaculty.org/guides/stat/Regression/Multicollinearity/Multicollinearity-1-lecture.pdf

gray dots in the x1-x2 plane, blue points hovering above, red pointed
arrows from gray to blue.

And then later on, say slide 36-60, I have regression planes drawn in
with the arrows from the plane to the points.

2. Use rgl based tools. These ones are especially neat if you want to
interact with the graph--"spin" a 3d graph or get a display with
lively colors.

It works more like plot, in the sense that you can draw the figure and
then add components with points3d and so forth.  And there are nice
working examples of extensions in misc3d.  And also, the R CMDR
interface has a working pull down menu system that can make rgl 3d
graphs.  That's a big plus.

After playing with some examples, I see these troubles. The only
output device that runs well (finishes and does not generate massive
files) is png.  The output quality on the screen is quite beautiful,
but transition to black-and-white is not as nice looking as persp, in
my opinion.  These graphs draw much more slowly.  They are more
difficult to script out in an Sweave document, it seems to me.

If those criticisms are wrong, I would be glad to know.

So I'm back wondering why persp can't be "updated".

Nobody has explained why it is not possible to revise persp to allow
expressions in axis labels.  Perhaps nobody has done it because people
think that persp has no fans :)   But I'm a fan.

--
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas

```