'mapview and plot show different output for the same rasterLayer, why?

Below is the rasterLayer RASTER_slope in a plot (4 NAs are shown in white):

enter image description here

Here is the metadata of RASTER_slope

class      : RasterLayer 
dimensions : 4, 4, 16  (nrow, ncol, ncell)
resolution : 500, 500  (x, y)
extent     : 2227000, 2229000, 1316500, 1318500  (xmin, xmax, ymin, ymax)
crs        : +proj=lcc +lat_0=12 +lon_0=-102 +lat_1=17.5 +lat_2=29.5 +x_0=2500000 +y_0=0 +datum=WGS84 +units=m +no_defs 
source     : memory
names      : values 
values     : -143.2145, 214.1981  (min, max)

Then I used mapview to get a dynamic visualization of RASTER_slope:

> mapview(RASTER_slope)
Warning messages:
1: In showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) :
Discarded ellps WGS 84 in Proj4 definition: +proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs +type=crs
2: In showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) :
Discarded datum World Geodetic System 1984 in Proj4 definition
3: In showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) :
Discarded ellps WGS 84 in Proj4 definition: +proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs +type=crs
4: In showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) :
Discarded datum World Geodetic System 1984 in Proj4 definition

The resulting mapview object looks like this:

enter image description here

The mapview object is displaying only 2 pixels with NA.

Probably I am wrong but I have the feeling that the key here is to pass a crs to RASTER_slope in a WKT format but I do not know how to do that.

Any help will be appreciated.



Solution 1:[1]

Following @dww, the key is in adding method="ngb" when calling mapview, no need to re project the rasterLayer, though. Here the code and output

mapview(RASTER_slope, method="ngb", na.color="transparent")

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Inder