I'm trying to create a perspective plot based on data I have, in longitude/latitude format.

The latitude and longitude are plotting correctly but the background is oddly black. How can I change that.
persp(lga_crop_05, expand =0.5, phi = 35, col= "lightblue", ticktype = "detailed")
That's the code where I create the plot. lga_crop_05 is my rasterlayer which contains the lat/long/values for my plot which I attached above.
I would appreciate any help. Thanks
What has gone wrong?
Nothing wrong with the code; but with our eyes. Try the following code:
## a function to produce a perspective plot
## "n" controls how refined your grid is
foo <- function(n) {
x <- seq(-1.95, 1.95, length = n)
y <- seq(-1.95, 1.95, length = n)
z <- outer(x, y, function(a, b) a*b^2)
persp(x, y, z, col = "lightblue")
}
If we have a 10 * 10 grid, the colour looks perfect.
foo(10)

If we have a 100 * 100 grid, the colour still looks OK.
foo(100)

Now, if we have extremely refined data, for example, on a 1000 * 1000 grid. Everything will just look like black.
foo(1000)

Note that you have a raster. I would suspect that your data are simply too refined. Have you checked how many cells you have in your lga_crop_05?
How to get around?
Set border = NA. Try modified function:
foo1 <- function(n) {
x <- seq(-1.95, 1.95, length = n)
y <- seq(-1.95, 1.95, length = n)
z <- outer(x, y, function(a, b) a*b^2)
persp(x, y, z, col = "lightblue", border = NA)
}

I used Mr.Li's example data, thank you. I think this is what you want.
# I changed x and y length irregular.
x <- seq(-1.95, 1.95, length = 500)
y <- seq(-1.95, 1.95, length = 200)
z <- outer(x, y, function(a, b) a*b^2)
# make persp.object and draw it
surf <- persp(x, y, z, col = "lightblue", border = NA, theta = -30)
# draw lines parallel to x axis. seq(...) depends on your data's length(y)
for(i in seq(10, 190, length=10)) lines(trans3d(x, y[i], z[,i], pmat = surf), col = "red")
# draw lines parallel to y axis. seq(...) depends on your data's length(x)
for(i in seq(25, 475, length=10)) lines(trans3d(x[i], y, z[i,], pmat = surf), col = "blue")

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With