2014-03-27 46 views
0

繪製地圖時,我可以繪製一個英國地圖ggmap有這樣一個觀點:大型白色邊框採用ggmap

library(ggmap) 
UK_map <- get_map(location = c(-2.65, 53.7), zoom = 5, maptype = "hybrid") 
UK_map <- ggmap(ggmap=UK_map, extent = "device", legend = "right") 
UK_map <- UK_map + geom_point(data = data.frame(x = -1.81, y = 55.655), aes(x, y), size = 5) 

而且我可以用溫斯頓·張的multiplot功能出兩個地塊在同一個窗口:

multiplot <- function(..., plotlist=NULL, cols) { 
    require(grid) 

    # Make a list from the ... arguments and plotlist 
    plots <- c(list(...), plotlist) 

    numPlots = length(plots) 

    # Make the panel 
    plotCols = cols       # Number of columns of plots 
    plotRows = ceiling(numPlots/plotCols) # Number of rows needed, calculated from # of cols 

    # Set up the page 
    grid.newpage() 
    pushViewport(viewport(layout = grid.layout(plotRows, plotCols))) 
    vplayout <- function(x, y) 
     viewport(layout.pos.row = x, layout.pos.col = y) 

    # Make each plot, in the correct location 
    for (i in 1:numPlots) { 
     curRow = ceiling(i/plotCols) 
     curCol = (i-1) %% plotCols + 1 
     print(plots[[i]], vp = vplayout(curRow, curCol)) 
    } 

} 

multiplot(UK_map, UK_map, cols = 2) 

enter image description here

但在使用時multiplot,大量白色邊框的上方和下方出現地圖,如附圖所示。有沒有辦法阻止這個白色邊框出現?

回答

0

我沒有使用multiplot,但方便的grid.arrange它是類似的,併產生類似的輸出 - 首先(即大的白色頂部/底部邊距)。

您可以更改圖形的設備的輸出高度/寬度得到你想要的東西,因爲它一開始將「中心」就在說選擇的圖形設備:(!不變)

png("map.png", width=480, height=240) 
grid.arrange(UK_map, UK_map, ncol=2) 
dev.off() 

產生如下map:

map