我想绘制一张我有两个变量的地图。一个是多边形,另一个是点。
多边形 - 省边界(name1、name2、name3、name4),
点 - 类(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(多边形)的图例。我怎样才能将它添加到点特征呢?