R: Mapping multiple Routes using ggmap

こ雲淡風輕ζ 提交于 2019-12-03 23:10:00

ok, so after a lot of noodling and modifying the above I finally settled on the looping solution that works:

leg <-function(start, dest, n){

    r<- route(from=start,to=dest,mode = c("walking"),structure = c("route"))  
    c<- geom_path(aes(x = lon, y = lat),
             alpha = 2/4, size = as.numeric(n)/500, data = r, colour = 'blue') 
    Sys.sleep(runif(1, 3.0, 7.5))
    return (c)
}

a <- qmap('Chicago', zoom = 12, maptype = 'road', color="bw")

for (n in 101:200){
    l<-leg(as.character(df[n,1]), as.character(df[n,2]),as.character(df[n,3])) 

    a<-a+l
}

a

this worked fairly well. the only bumps were when it the google api would reject the call. after I added the random variable sys.sleep in there it worked without a hitch. That said, I still never tried more than 150 at a go (limited my mapping to a sample of the top 10% of routes for ease of visual and for function). Finally after some happy illustrator time I ended up with a good looking map. Thanks to the community for the interest and for providing the looping idea.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!