我想要繪製在谷歌地圖的線路層。如何繪製SpatialLinesDataFrame特徵映射在谷歌地圖
數據
> dput(map)
new("SpatialLinesDataFrame"
, data = structure(list(att = c(463643, 2291491, 315237340, 10348934,
309845150, 674351, 58057, 55962, 302861, 1405635)), .Names = "att", row.names = c(NA,
10L), class = "data.frame")
, lines = list(<S4 object of class structure("Lines", package = "sp")>,
<S4 object of class structure("Lines", package = "sp")>,
<S4 object of class structure("Lines", package = "sp")>,
<S4 object of class structure("Lines", package = "sp")>,
<S4 object of class structure("Lines", package = "sp")>,
<S4 object of class structure("Lines", package = "sp")>,
<S4 object of class structure("Lines", package = "sp")>,
<S4 object of class structure("Lines", package = "sp")>,
<S4 object of class structure("Lines", package = "sp")>,
<S4 object of class structure("Lines", package = "sp")>)
, bbox = structure(c(50.497608475813, 26.1186426230732, 50.6164182652142,
26.2649832975207), .Dim = c(2L, 2L), .Dimnames = list(c("x",
"y"), c("min", "max")))
, proj4string = new("CRS"
, projargs = "+proj=longlat +ellps=WGS84 +towgs84=0,0,0,-0,-0,-0,0 +no_defs"
)
)
方法
library(rgdal)
library(ggmap)
gmap <- get_map(location=rowMeans(bbox(segMap)), zoom = 11) # get Google map to use as background
變我
plot(map, col = map$att, lwd = 1.5)
plot(gMap)
變II
plot(map, col = map$att, lwd = 1.5)
ggmap(gMap)
問題
背景地圖繪製在特徵圖的頂部,而不是象背景,作爲結果的特徵圖是不可見的。 爲了澄清,無論是劇情要求(plot()
和ggmap
)做工精細獨立。 謝謝
如果你真的想使用'ggmap',你應該認真考慮使用'ggplot2'中的函數,'ggmap'基於(根據語法),更重要的是,這兩個包完美地協同工作(看看'ggplot2 :: geom_line()','geom_polygon()'和'fortify()')。如果您不想使用ggplot語法,請使用'openstreetmap'包,'rGooglemaps'等。 – maj
Thanks @maj。我是否理解使用ggmap是避免使用gis路線的一種方法?如果我也想做一些空間分析,你會推薦什麼解決方案? – jpinelo
@jpinelo他們不是相互排斥的。您可以將多邊形和地圖圖層添加到ggmap創建的ggplot和'sp'對象的'dput's(如您所見)不能很好地傳輸。這樣的答案是一個好的例子http://stackoverflow.com/questions/10930737/ggmap-with-geom-map-superimposed/10940778#10940778 – hrbrmstr