我使用库(RgoogleMaps)在地图(点)上绘制测量位置。不同的点有不同的装备,我成功地获得了每个装备单独颜色的点:
theplot <- PlotOnStaticMap(lat=sitecoord$lat, lon=sitecoord$lon,
cex=.7, pch=20,
col=sitecoord$equipmentType,
MyMap=Map, NEWMAP=FALSE)
如何向生成的地图图添加图例,以查看哪些设备由蓝点表示,哪些由红色点表示,等等?
更新:
使用@Rguy 的非常好的建议。我设法获得了图例。为了他人的利益,这是我的测试代码(不,我不是在冰岛进行测量,只是将其用作示例):
library(RgoogleMaps)
library(RColorBrewer)
Equipment <- c("AA","AA","BB","CC")
lat <- c(63.90,66.20,64.80,64.50)
lon <- c(-22.40,-14.20,-18.60,-15.00)
tblDataPoints <- data.frame(Equipment,lat,lon)
My.Pal <- brewer.pal(3, "Reds")
tblDataPoints$colorz <- My.Pal[tblDataPoints$Equipment]
plot.new()
bb <- qbbox(lat=range(tblDataPoints$lat), lon=range(tblDataPoints$lon))
m <- c(mean(tblDataPoints$lat), mean(tblDataPoints$lon))
zoom <- min(MaxZoom(latrange=bb$latR,lonrange=bb$lonR))
Map <- GetMap.bbox(bb$lonR, bb$latR, zoom=zoom, maptype="roadmap", NEWMAP=TRUE)
tmp <- PlotOnStaticMap(lat=lat, lon=lon, cex=.7, pch=20, col=tblDataPoints$colorz, MyMap=Map, NEWMAP=FALSE)
tblLgd <- unique(tblDataPoints[,c("Equipment","colorz")])
row.names(tblLgd) <- NULL
legend("topright", legend = tblLgd$Equipment, fill = tblLgd$colorz, bg = "white")