1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| library(raster) ; library(rgdal) ; library(sp);library(rgeos);library(ggplot2)
# importer raster
alti=raster("raster.tif")
# Convert rasters TO dataframes for plotting with ggplot
hdf <- rasterToPoints(alti)
hdf <- data.frame(hdf)
colnames(hdf) <- c("Long","Lat","Altitude")
# Plot layer with ggplot()
ggplot()+
layer(geom="raster",data=hdf,mapping=aes(Long,Lat,fill=Altitude))+
# draw boundaries
geom_path(color="black", linestyle=0.2)+
# legend
scale_fill_gradientn(name="A",colours=c("red","blue","green","grey","yellow","orange","black"), breaks=c(0,100,200,500,2000,4000,5000)) |
Partager