Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spplot: put labels on the map

Tags:

r

spatial

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

like image 393
user3817704 Avatar asked Aug 05 '14 18:08

user3817704


1 Answers

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

 list("sp.text", coordinates(x), label, cex=0.5, col="green")
like image 67
user3817704 Avatar answered Sep 29 '22 12:09

user3817704