I have this dataframe, df that represents the locations of 3 people:
df <- read.csv(text = "name,lat,long
Tom,42,-73
Sally,41,-72
Harry,41,-74")
I have some code that produces a map per person, centred on the person's location:
Map(function(x, y, z) {
ggmap(get_map(location = c(lon = x, lat = y), zoom = 15, color = "color", source = "google", scale = 2),size = c(1900, 1900), extent = "device") +
geom_point(data = df[z,], aes(x = long, y = lat), color = "red") +
ggtitle(df$name[z]) +
theme(plot.title = element_text(hjust = 0.5))
}, df$long, df$lat, seq_along(df))
This works just fine for producing the maps in the R console, but I'd like to save each one out using ggsave. I'm unsure how to do this, although I have tried to specify as high-res, 1900 x 1900 and scale = 2 . I'd also like to name each of the files with the corresponding value of df$name and save into a directory relative to the working directory of /Maps/ .