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]]
> p[[2]]
> p[[3]]
notes:
- you had
zoom = 12, ... source = "osm"
insidelocation = c(...)
argument. these should argumentsget_map()
. - for reason got error openstreetmap (http status '400 bad request'), used default google maps instead.
Comments
Post a Comment