如何在R中的Google地图上为绘制点添加标签

时间:2015-05-07 23:20:51

标签: r google-maps labels

我想为在R中的谷歌地图上绘制的点添加标签。我该怎么办?

这是我的数据框的子集

>dput(data[1:10,])
structure(list(ID = structure(c(24L, 6L, 13L, 14L, 22L, 25L, 
27L, 3L, 7L, 11L), .Label = c("ALB", "ANG", "BBR", "BNF", "BRK", 
"BTG", "CAL", "CAM", "CANV", "CEP", "CHW", "CSS", "DRP", "EAT", 
"FMM", "FRC", "GCB", "GRPR", "HIN", "KFO", "KZR", "LRK", "LSN", 
"MON", "NAP", "OLO", "OLY", "PEO", "POTR", "POW", "SFRG", "WWA", 
"WWW"), class = "factor"), lat = c(48.9434667, 45.775269, 46.442597, 
45.76697, 46.903737, 46.58292, 47.9306472, 44.3772, 44.530811, 
47.4886), lon = c(-114.4125667, -122.558005, -122.907106, -122.514018, 
-123.0178, -122.87845, -123.3565361, -121.6536, -123.145594, 
-117.5786), size = c("tiny", "tiny", "tiny", "tiny", "tiny", 
"tiny", "tiny", "tiny", "tiny", "tiny"), col = c("red", "red", 
"red", "red", "red", "red", "red", "red", "red", "red"), char = c("", 
"", "", "", "", "", "", "", "", "")), .Names = c("ID", "lat", 
"lon", "size", "col", "char"), row.names = c(NA, 10L), class = "data.frame")

基本上我想添加" ID"标签旁边的名字。

这是我的代码

data$size <- "tiny"  #create a column indicating size of marker
data$col <- "red"   #create a column indicating color of marker
data$char <- ""   #normal Google Maps pinpoints will be drawn
names(data) <- c("ID", "lat", "lon", "size", "col", "char")  #assign column headings
bb <- qbbox(lat = data[,"lat"], lon = data[,"lon"])
zoom <- min(MaxZoom(latrange=bb$latR,lonrange=bb$lonR))
MyMap <- GetMap.bbox(bb$lonR, bb$latR, MINIMUMSIZE = FALSE, zoom = 5, markers = data, destfile = "MyTile4.png", maptype = "terrain") 

最后这是我从上面的代码中得到的地图

test map

0 个答案:

没有答案