spplot: put labels on the map
Asked Answered
R

1

7

I seek help on how to change font size and font color for sp.text labels on the attached map—to avoid overlapping of labels and to improve readability.

Map was produced as below. If needed, one may download the SpatialPolygonsDataframe object 'mymap' here.

trellis.par.set() is not solving 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

Rosetterosewall answered 5/8, 2014 at 18:19 Comment(1)
The link to the 'mymap' object is broken, so there's no way to reproduce the output. It would be nice if you could do something about it.Uganda
R
4

Found the solution: Needed to add cex, col arguments in the list:

 list("sp.text", coordinates(x), label, cex=0.5, col="green")
Rosetterosewall answered 5/8, 2014 at 18:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.