library(ggplot2)
library(terra)
## Simple grey scale annotation
ggR(rlogo)
## With linear stretch contrast enhancement
ggR(rlogo, stretch = "lin", quantiles = c(0.1,0.9))
## ggplot with geom_raster instead of annotation_raster
## and default scale_fill*
ggR(rlogo, geom_raster = TRUE)
## with different scale
ggR(rlogo, geom_raster = TRUE) +
scale_fill_gradientn(name = "mojo", colours = rainbow(10)) +
ggtitle("**Funkadelic**")
## Plot multiple layers
# \donttest{
ggR(lsat, 1:6, geom_raster=TRUE, stretch = "lin") +
scale_fill_gradientn(colors=grey.colors(100), guide = "none") +
theme(axis.text = element_text(size=5),
axis.text.y = element_text(angle=90),
axis.title=element_blank())
## Don't plot, just return a data.frame
df <- ggR(rlogo, ggObj = FALSE)
head(df, n = 3)
## Layermode (ggLayer=TRUE)
data <- data.frame(x = c(0, 0:100,100), y = c(0,sin(seq(0,2*pi,pi/50))*10+20, 0))
ggplot(data, aes(x, y)) + ggR(rlogo, geom_raster= FALSE, ggLayer = TRUE) +
geom_polygon(aes(x, y), fill = "blue", alpha = 0.4) +
coord_equal(ylim=c(0,75))
## Categorical data
## In this case you probably want to use geom_raster=TRUE
## in order to perform aestetic mapping (i.e. a meaningful legend)
rc <- rlogo
rc[] <- cut(rlogo[[1]][], seq(0,300, 50))
ggR(rc, geom_raster = TRUE)
## Legend cusomization etc. ...
ggR(rc, geom_raster = TRUE) + scale_fill_continuous(labels=paste("Class", 1:6))
# }
## Creating a nicely looking DEM with hillshade background
terr <- terrain(srtm, c("slope", "aspect"))
hill <- shade(terr[["slope"]], terr[["aspect"]])
ggR(hill)
ggR(hill) +
ggR(srtm, geom_raster = TRUE, ggLayer = TRUE, alpha = 0.3) +
scale_fill_gradientn(colours = terrain.colors(100), name = "elevation")
Run the code above in your browser using DataLab