spplot:在地图上放置标签

时间:2014-08-05 18:19:30

标签: r spatial

我在如何为附加地图上的sp.text标签更改fontsize和fontcolor方面寻求帮助。避免标签重叠,提高可读性。

地图的制作如下。如果需要,可以下载spatialpolygonsdataframe'mymap'here

trellis.par.set()没有解决我的问题,我使用不正确吗?

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

1 个答案:

答案 0 :(得分:4)

找到解决方案:需要在列表中添加cex,col参数:

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