2015-10-05 35 views
0

打印逐個而不是在一個行使用此代碼時我希望得到所有的打印出現在一行。相反,他們一一打印。地圖使用ggmap循環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) 
    } 
+2

您需要使用'gridExtra :: grid.arrange'。您正在混合基本圖形和網格圖形,並且不會按預期工作。 – hrbrmstr

+0

好的。我會在哪裏把它放入循環? –

回答

0

喜歡的東西:

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設置。

+0

它運行,但似乎沒有劇情...... –

+1

DID工作。額外的輸出風在後臺打開! –