0

I'm trying to implement a 3D plot in R using the rsm package's persp() function. I'd like to add contour lines to the base of the plot, for example like here: Draw a line after persp using rsm in R

The rsm documentation says this should be possible:

In persp, contour lines may be added via the contours argument. It may be a boolean or character value, or a list. If boolean and TRUE, default black contour lines are added to the bottom surface of the box

https://cran.r-project.org/web/packages/rsm/rsm.pdf

When I do this, I get a warning and no contours, although the 3D plot generates just fine: "Warning message: In persp.default(a, t, q, contours = ("top") : "contours" is not a graphical parameter

I was able to get this pattern working using code here: Is there a way to create a 3d plot with contours beneath the plot in R?

But it would be nice to know why the rsm package doesn't (appear to) work as advertised, unless I'm doing something wrong?

Here is my MWE:

library(rsm)

surface <- function(a, t){
  q <- (4*40)/(4*a^2 + 4*a*t^2 + t^4 + 4*40)
}

a <- seq(.00001, 5, length= 20)
t <- seq(.00001, 5, length= 20)
q <- outer(a, t, surface)

persp(a, t, q,
      contours=("top"))

persp(a, t, q,
      contours=T)

beddotcom
  • 447
  • 3
  • 11
  • 2
    In `rsm`, `persp()` is actually `persp.lm()`, and its first two arguments are a lm object and a formula. Because you are passing vectors to `persp()`, you are actually calling `graphics::persp()`, which does not have a `contours` argument. Hence the warning. Have a look at `?rsm::persp.lm` for more information. – meriops Dec 17 '20 at 09:15
  • That's right. Just to emphasize this point, you can't use contour.lm to do contours of data. You have to fit a model; then you see contours of the fitted model, not of the raw data. Those can be quite different. – Russ Lenth Jan 16 '21 at 02:00

0 Answers0