r - Producing a map for each location row using ggmap -


i have dataframe:

df <- read.csv(text = "name,lat,long tom,42,-73 sally,41,-72 harry,41,-74") 

that has lat long of 3 people. using ggmap i'd produce map per row, in case show location of each of 3 people.

i've used ggmap before, go-to code of:

ggmap(get_map(location = c(lon = lon, lat = lat,                             zoom = 12, color = "bw", source = "osm"))) +   geom_point(data=df, aes(x=longitude,y=latitude), color='red') 

...doesn't work event pull map , centre it. i'd first centre map on person's location, drop point @ central location, 3 maps output.

thanks.

we can loop through data frame produce 1 map per row:

library(ggmap)  p <- vector("list", 3)  (i in seq_along(df)){   p[[i]] <- ggmap(get_map(location = c(lon = df$lon[i], lat = df$lat[i]),                       zoom = 12, color = "bw", source = "google")) +     geom_point(data=df[i,], aes(x=long, y=lat), color='red') }  > p[[1]] 

plot1

> p[[2]] 

plot2

> p[[3]] 

plot3

notes:

  1. you had zoom = 12, ... source = "osm" inside location = c(...) argument. these should arguments get_map().
  2. for reason got error openstreetmap (http status '400 bad request'), used default google maps instead.

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -