1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| invisible(sapply(
##"sp" est une dépendance de "raster", ce n'est pas la peine de l'attacher explicitement
c("raster", "rgdal", "rgeos", "ggplot2"),
function(x) library(x, character.only = TRUE)
))
alti <- raster("raster.tif")
hdf <- rasterToPoints(alti)
colnames(hdf) <- c("Long","Lat","Altitude")
hdf <- as.data.frame(hdf)
ggplot() +
layer(geom = "raster",
data = hdf,
mapping = aes(Long, Lat, fill = Altitude)
) +
geom_path(color = "black", linestyle = 0.2) +
scale_fill_gradientn(
name = "A",
colours = c("red", "blue", "green", "grey", "yellow", "orange", "black"),
limits = c(0, 5000)
) |
Partager