0

我可以用这样的点绘制一张英国地图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)

我可以使用 Winston Chang 的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)

在此处输入图像描述

但是在使用 时multiplot,地图上方和下方会出现一个大的白色边框,如附图所示。有没有办法阻止这个白色边框出现?

4

1 回答 1

-1

我没有使用multiplot,但grid.arrange它是相似的并产生相似的输出 - 起初(即大的白色顶部/底部边距)。

您可以更改图形设备的输出高度/宽度以获得所需的内容,因为它最初会将其“居中”到所述选定的图形设备上:

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

生成以下(未触及!)地图:

地图

于 2014-03-27T11:11:52.433 回答