Search code examples
rrgl

Incorrect coordinates in persp3D plot with bathy class object


I'm trying to plot an object of the bathy class using a persp3D but, although the surface it is correct in the plot, the axis coordinates are wrong.

library(OceanView)
library(marmap)

bathy<- getNOAA.bathy(lon1 = -90, lon2 = -60, lat1 = 20, lat2 = 29, resolution = 2, keep = T)

persp3D(z=bathy, col= jet.col (n = 100, alpha = 1), colkey=T, scale = F, 
        expand=0.05, plot = FALSE, xlab="longitude", 
          ylab="latitude", zlab="depth")

plotrgl(lighting = TRUE, smooth = TRUE) 

figure example

How can I fix this? I tried to convert the bathymetric data to other object class, such as xyz or RasterLayer, in order to define the x and y parameters but then I was unable to plot it.


Solution

  • I think the problem is the way persp3d understands bathy when only z is passed. See x, y, z arguments in ?persp3d. If you also pass x and y, then the axes are fine. With the minimal persp3d example we have:

    persp3d(x=seq(-90, -60, length=nrow(bathy)),
            y=seq(20, 29, length=ncol(bathy)),
            z=bathy)