1
votes

I want to plot a discontinuous surface using the persp function.

Here is the function:

f <- function(x, y)
{
  r <- sqrt(x^2 + y^2)
  out <- numeric(length(r))
  ok <- r >= 1
  out[ok] <- exp(-(r[ok] - 1))
  return(out)
}

To get a perspective plot of the function on a regular grid, I use

x <- y <- seq(-4, 4, length.out = 50)
z <- outer(x, y, f)
persp(x, y, z, , theta = 30, phi = 30, expand = 0.5, col = "lightblue")

The resulting plot does not properly show the circular nature of discontinuity points of the surface. Any suggestion about how to obtain a better perspective plot, instead of contour plot or image?

1

1 Answers

0
votes

If something interactive works for you, I would go for something like this:

library(plotly)
plot_ly(z = ~ z) %>% add_surface()

Because the circular nature is best seen from above, a phi of 90 would be best to highlight this feature, but then you lose the rest of the shape and it is pretty useless. Hence, I would go for something interactive.

persp(x, y, z, , theta = 30, phi = 30, expand = 0.5, col = "lightblue")

Persp Plot