Display of Geospatial raster in R
Let’s load an image from a Sentinel satellite that contains 4 spectral bands. Saving the file is described in the previous post.
r = stack("F:/B_all.tif")
First, display a band with:
plot( r[[1]] )
The raster is displayed in the default color palette on the Plots tab of RStudio.
To display the raster in grayscale, the col attribute must be added to the plot function:
plot( r[[1]], col = grey.colors(255) )
gray.colors() is a palette of grays, and the number 255 indicates the number of shades.
To plot the raster in the color composition, you can use the plotRGB(x, r, g, b, stretch) function, where x – the name of the variable with the multicband raster, r – the number of a single raster for the R band, g – the number of a single raster for the G band, B – the number of a single raster for the B band, stretch – for images with radiometric resolution above 8 bits, it is necessary to degrade this resolution by defining the type of post-processing). For more information, see the description of the plotRGB function.
plotRGB(b_all, 3, 2, 1, “lin”)
After executing the function we see the composition in real colors: