我想绘制一张地图,其中有两个变量。一个是多边形,另一个是点。
polygon - 省边界(name1,name2,name3,name4),
point - class(a,b,c,d)
因为我必须将它们一起绘制,我需要两个传说。下面是我获得面要素的图例的代码。请建议如何为点要素添加图例。
#importing shp files
states = readOGR ( dsn = "C:/.../shp", layer = "states")
river = readOGR ( dsn = "C:/.../shp", layer = "Province")
stations = readOGR ( dsn = "C:/.../shp", layer = "ganga_stations_prj")
r <-list("sp.lines", river, pch = 10, cex= 2, col = "blue" ) # line feature
map = function(x, ...)
{
scale = list("SpatialPolygonsRescale", layout.scale.bar(),
offset = c(800000, 2480000), scale = 300000, fill=c("transparent","black"))
text1 = list("sp.text", c(800000,2520000), "0")
text2 = list("sp.text", c(1100000, 2520000), "200 km")
arrow = list("SpatialPolygonsRescale", layout.north.arrow(),
offset = c(1800000,3300000), scale = 100000)
spplot(states, "NAME_1", sp.layout=list(scale,text1,text2, arrow, r, x),main = "Human Use Classification")
}
stations@data$Colour[stations@data$Class=="a"]="yellow"
stations@data$Colour[stations@data$Class=="b"]="green"
stations@data$Colour[stations@data$Class=="c"]="blue"
stations@data$Colour[stations@data$Class=="d"]="red"
p <-list("sp.points", stations,pch=18, cex=1.5, col=stations@data$Colour)
map(p)
我得到的地图:
正如你所看到的那样只有PROVINCE(多边形)的传说。我可以将它添加到点特征吗?
答案 0 :(得分:1)
我不熟悉spplot,但通常你可以使用图例:
legend("bottomright", legend=c("a","b","c","d"), pch=18, col=c("yellow","green","blue","red"))
答案 1 :(得分:-1)
尝试legend.grid()
包中的grid
功能。它对我有用,并感谢你提出这个问题。