Search code examples
rplotrasterr-raster

Changing the titles within a raster stack


I had created a raster stack when plotted looks like this: enter image description here

I would like to change the titles on each of these graphs, and add a main title to it.

levelplot(rs, main = "MD13U0001", col.regions=rev(terrain.colors(6)), names.attr=c("LoCoH", "Elevation"))

When I try using the function levelplot it gives me this: enter image description here

It puts both plots into the same scale, but gives me what I want in relation to the titles. Is there a better function that will give me the titles, but not keep the scales separate?


Solution

  • Example data

    library(raster)
    s <- stack(system.file("external/rlogo.grd", package="raster"))[[1:2]]
    

    Set layer names and default plot

    names(s) <- c("Apple", "Mango")
    plot(s, cex.main=.8)
    

    Some example customization

    par(mar=c(3,3,5,5), mfrow=c(1,2))
    for (i in 1:2) {
        plot(s[[i]], cex.axis=.75, las=1)
        title(names(s)[i], line=0.5, cex.main=0.8)
    }
    text(-40, 100, "These are my maps", xpd=NA, cex=2)
    

    enter image description here