Spplot: stick labels on the map

I am looking for help changing fonts and fontcolor for sp.text labels on an attached map. To avoid overlapping labels and improve readability.

The map was prepared as shown below. If necessary, you can download spatial information about the 'mymap' plugins here .

trellis.par.set () does not solve my problem, am I using it incorrectly?

library(sp)
library(latticeExtra)

# Create list object for sp.layout (Got these functions here on stackoverflow, thank you owner)
sp.label <- function(x, label) {list("sp.text", coordinates(x), label)}
NUMB.sp.label <- function(x) {sp.label(x, as.vector(x@data$NUMB))}
make.NUMB.sp.label <- function(x) {do.call("list", NUMB.sp.label(x))}


# Spplot
tps <- list(fontsize=list(text=5), fontcolor=list(text="green"))
trellis.par.set(tps)

spplot(mymap, "indic", 
                col.regions=c("#D3D3D3","#A9A9A9"),
                sp.layout = make.NUMB.sp.label(mymap), 
                cex = 0.5,
                bg = "white", col="light grey", border="light grey")

enter image description here

+4
source share
1 answer

Found a solution: you need to add the arguments cex, col to the list:

 list("sp.text", coordinates(x), label, cex=0.5, col="green")
+4
source

All Articles