Search code examples
rmatrixplotasciiraster

Plotting a big raster file results in a white frame


I am currently working with an ASCII matrix of 256x256 pixels. I correctly imported it into R, rasterized it and the values are what I would expect (i.e., correct x and y boundaries and min and max "z" values). However, while plotting it I get a blank raster, like every value in the matrix is zero.

I tried by creating another file as a 5x5 matrix and I get no problem with that. Am I missing something?

Files and screenshots below: my 256x256 raster

https://gofile.io/d/JGApXI ascii matrix link


Solution

  • Your raster is simply almost empty, in the sense that it has just the 2% of values !=0. However if you export the raster and visualize it in a GIS software (like Qgis, or ArcMap), by setting a 100% transparency for the 0 values you can see the remaining values:

    Here an example:

    library(raster)
    x <- read.table("D:/muon sideways0000.txt")
    x <- as.matrix(x)
    r <- raster(x)
    writeRaster(r,"D:/r.tif")
    z <- apply(x, 1, function(x)sum(x!=0))
    sum(z)/ncell(r)*100
    

    enter image description here