所以我试图使用for循环输出许多谷歌地图。
奇怪的是,如果我键入(i = 1; i = 2)
它可以正常工作,但是如果我使用for循环那就不行了!
## THIS WORKS:
rand.coord <- cbind(rnorm(10, 40, 40),lat=rnorm(10, 40, 40))
i = 1
df <- data.frame(cbind(lon=rand.coord[i,1],lat=rand.coord[i,2] ))
map <- get_map(location = df, source = "google", zoom = 4, scale = 2,
maptype = "satellite")
ggmap(map)
i = 2
df <- data.frame(cbind(lon=rand.coord[i,1],lat=rand.coord[i,2] ))
map <- get_map(location = df, source = "google", zoom = 4, scale = 2,
maptype = "satellite")
ggmap(map)
#THIS DOES NOT WORK:
for ( i in 1:10){
df <- data.frame(cbind(lon=rand.coord[i,1],lat=rand.coord[i,2] ))
map <- get_map(location = df, source = "google", zoom = 4, scale = 2,
maptype = "satellite")
ggmap(map)
}