Search code examples
rplotgislatticer-sp

How to remove zcol boxes in spplot?


I would like to remove the box around the variable names in spplot ("cadmium", "copper",... in the example below), or at least change their the peach color.

library(sp)
rv = list("sp.polygons", meuse.riv, fill = "lightblue")
scale = list("SpatialPolygonsRescale", layout.scale.bar(), 
offset = c(180500,329800), scale = 500, fill=c("transparent","black"), which = 4)
text1 = list("sp.text", c(180500,329900), "0", cex = .5, which = 4)
text2 = list("sp.text", c(181000,329900), "500 m", cex = .5, which = 4)
arrow = list("SpatialPolygonsRescale", layout.north.arrow(), 
offset = c(181300,329800), 
scale = 400, which = 4)
cuts = c(.2,.5,1,2,5,10,20,50,100,200,500,1000,2000)
spplot(meuse, c("cadmium", "copper", "lead", "zinc"), do.log = TRUE,
key.space = "right", as.table = TRUE,
sp.layout=list(rv, scale, text1, text2, arrow), # note that rv is up front!
main = "Heavy metals (top soil), ppm", cex = .7, cuts = cuts)

Example image from https://edzer.github.io/sp/


Solution

  • the spplot calls the trellis graphics, so you can pass additional parameters for the zcols (called strips) using par.settings. For a full list of parameters you can pass, check table 23.3 of lattice manual. You would specify them in a list like i show below:

    my.settings <- list(
      strip.background=list(col="lightblue"),
      strip.border=list(col="transparent")
    )
    
    spplot(meuse, c("cadmium", "copper", "lead", "zinc"), do.log = TRUE,
    key.space = "right", as.table = TRUE,
    sp.layout=list(rv, scale, text1, text2, arrow), # note that rv is up front!
    main = "Heavy metals (top soil), ppm", cex = .7, cuts = cuts,
    par.settings=my.settings)
    

    enter image description here