library(ggmap) library(TSP) concorde_path("/home/user") sc <- read.table("/home/user/R/work/sc.csv", header=TRUE, sep=",", na.strings="NA", dec=".", strip.white=TRUE) names(sc)<-c("name","address","lat","lon") nr<-nrow(sc) load("/home/user/R/work/JPN/distance.dat") rownames(distance)<-sc$name colnames(distance)<-sc$name shortest<-solve_TSP(TSP(ATSP(distance)), method ='concorde') lat=sc$lat lon=sc$lon map <- get_googlemap(center=c(139,35),zoom=5) map<-ggmap(map)+geom_point(data=sc,mapping=aes(x=lon,y=lat),size=2,colour="red") travelmode="driving" for(i in 1:(nr-1)){ h1=shortest[i] h2=shortest[i+1] route1=na.omit(route(c(lon[h1],lat[h1]),c(lon[h2],lat[h2]),mode=travelmode,structure="route")) print(route1) map=map+geom_path(data=route1,aes(x=lon,y=lat),size=0.75,colour="blue",alpha=0.75) } h1=shortest[nr];h2=shortest[1] route1=na.omit(route(c(lon[h1],lat[h1]),c(lon[h2],lat[h2]),mode=travelmode,structure="route")) print(route1) map=map+geom_path(data=route1,aes(x=lon,y=lat),size=0.75,colour="blue",alpha=0.75) map
|