- given addresses
 
- find long and lat 
 
- get a map of the city
 
- plot point at location of the addresses
 
library(ggmap)
library(stringr)
mystreets <- read.table("streets.txt",header=F,sep="|")
head(mystreets) ## addresses of physicians in Leipzig
                          V1
1  Rosa-Luxemburg-Str. 20-30
2            Marktstraße 2-6
3       Engelsdorfer Str. 21
4               Jahnallee 59
5            Johannisplatz 1
6         Hugo-Krone-Platz 9
## adds city and country to get complete addresses
ads <- paste(mystreets$V1, ', Leipzig, Germany',sep='')
## get rid of space at begin and end of the strings
ads <- str_trim(ads)
## get long and lat from google so you 
## need to have access to the internet
gc <- geocode(ads)
## get data of leipzig (limits of the map)
leipzig <- geocode("leipzig",output="more")
## get map from cloudmademap, also possible googlemaps etc
## for cloudemademap you need additionaly a api key
map <- get_cloudmademap(bbox=c(left=leipzig$west,
                          bottom=leipzig$south,
                          right=leipzig$east,
                          top=leipzig$north),
                        maptype = 997,api_key = api_key,zoom=13)
## plot all together
ggmap(map) + geom_point(aes(x=lon,y=lat),colour="red",data=gc)  
 
0 comments:
Post a Comment