oscarperpinan / rastervis

The raster package defines classes and methods for spatial raster data access and manipulation. The rasterVis package complements raster providing a set of methods for enhanced visualization and interaction.
oscarperpinan.github.io/rastervis
GNU General Public License v3.0
85 stars 26 forks source link

Plot RGB raster with gplot #73

Closed Saadi4469 closed 3 years ago

Saadi4469 commented 3 years ago

Hello,

How can I plot an RGB raster with gplot? For plotting RGB rasters, I usually use plotRGB from the raster package. But, now I am trying to plot it via gplot so I can add other ggplot2 functions in the plot object.

Thank you,

oscarperpinan commented 3 years ago

Hello,

This functionality is not included in rasterVis. You may try RStoolbox::ggRGB or terrainr::geom_spatial_rgb.

rhijmans commented 3 years ago

There is also terra::RGB2col to go from RGB to a single layer with a color-table. But I do not think that rasterVis looks at color tables; and I am not sure if any other package does that for ggplot mapping.

Saadi4469 commented 3 years ago

Thank you both, and also thanks a bundle for making this package. Normally, I had to first convert a raster into a df to plot with ggplot2, and for high resolution rasters, that's inefficient in terms of memory use. But, your package maybe also does that in the background, but is so well optimized that I don't run into any memory issues no matter how big the raster is.

rhijmans commented 3 years ago

Regular sampling is used for large rasters.

With raster this is used

      maxpixels=50000
      x <- raster::sampleRegular(x, maxpixels, asRaster = TRUE)

And with terra

     x <- terra::spatSample(x, maxpixels, "regular", as.raster = TRUE)