R plot background map from Geotiff with ggplot2
Here is an alternative using function gplot
from rasterVis
package.
library(rasterVis)
library(ggplot2)
setwd("C:/download") # same folder as the ZIP-File
map <- raster("smr25musterdaten/SMR_25/SMR_25KGRS_508dpi_LZW/SMR25_LV03_KGRS_Mosaic.tif")
gplot(map, maxpixels = 5e5) +
geom_tile(aes(fill = value)) +
facet_wrap(~ variable) +
scale_fill_gradient(low = 'white', high = 'black') +
coord_equal()
If you want to use the color table:
coltab <- colortable(map)
coltab <- coltab[(unique(map))+1]
gplot(map, maxpixels=5e5) +
geom_tile(aes(fill = value)) +
facet_wrap(~ variable) +
scale_fill_gradientn(colours=coltab, guide=FALSE) +
coord_equal()
With colors: