I'm trying to plot a line layer over Google maps.
Data
> 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"
)
)
Approach
library(rgdal)
library(ggmap)
gmap <- get_map(location=rowMeans(bbox(segMap)), zoom = 11) # get Google map to use as background
Variant I
plot(map, col = map$att, lwd = 1.5)
plot(gMap)
Variant II
plot(map, col = map$att, lwd = 1.5)
ggmap(gMap)
Problem
Background map is plotted on top of feature map, rather than as background, as a result feature map is not visible.
To clarify, both plot calls ( plot() and ggmap) work fine independently.
Thank you

ggmap, you should seriously consider also using the functions fromggplot2, whichggmapis based on (in terms of the syntax) and more importantly, the two packages work together perfectly (have a look atggplot2::geom_line(),geom_polygon()andfortify()). If you do not want to use ggplot syntax, rather go with theopenstreetmappackage,rGooglemapsetc. - majdputs ofspobjects (as you can see) don't transport well. This SO answer is an OK example stackoverflow.com/questions/10930737/… - hrbrmstr