使用 ggmap loop mfrow 一张一张地打印地图而不是一行打印

Maps printing one by one and not in one row using ggmap loop mfrow

使用此代码时,我希望所有打印都显示在一行中。相反,他们一张一张打印。

谁能发现我的错误??

par(mfrow=c(1,8))
(e<-bbox(extent(data3)))
m <- get_map(e, zoom=11, source="google", maptype = "terrain")

# 
# for(i in 1:length(subs10_latlong)) # all periods
for(i in 2:8) # Not first and last period
{
  # subs10_latlong.df <- as(subs10_latlong[[i]], "data.frame")
  m <- get_map(e, zoom=11, source="google", maptype = "terrain")
  p <- (ggmap(m) + geom_point(data=as(subs10_latlong[[i]], "data.frame"), aes(x=location.long, y=location.lat, colour = trackId)))
  print(p)
  }

类似于:

lapply(2:8, function(i) {

  m <- get_map(e, zoom=11, source="google", maptype = "terrain")
  p <- ggmap(m) 
  p <- p + geom_point(data=as(subs10_latlong[[i]], "data.frame"), 
                      aes(x=location.long, y=location.lat, colour = trackId))
  p

}) -> gplots

do.call(grid.arrange, c(gplots, ncol=8))

模仿您的 par 设置。