使用视口对齐晶格和 tmap 输出

Align lattice and tmap outputs using viewports

我正在尝试对齐几个面板(2 个地图)和包 openair 的网格输出,以及一些使用网格的解释性文本:

但是,我希望点阵输出的左边距与左上角地图的左边缘对齐,文本与右上角地图的左边距对齐。

理想情况下,我想得到这个:

我使用的代码是这样的:

library(tmap)
library(tmaptools)
library(openair)
library(grid)
library(gridExtra)


london_map <- qtm(read_osm("London"))
london_terrain <- qtm(read_osm("London", type = "stamen-terrain"))

pp_plot <- polarPlot(mydata, type="season")
top.vp <- 
  viewport(layout=grid.layout(3, 11,
                              heights=unit(c(0.5, 3.5 ,4), "inches"),
                              widths=unit(c(1,1,1,1,1,1,1,1,1,1), "inches")))


png(filename = "test.png", width = 11, height = 8, units ="in", res=72)

grid.newpage()
pushViewport(top.vp)
print(london_map, vp = viewport(layout.pos.row = 2, layout.pos.col=1:5, just="left"))
print(london_terrain, vp = viewport(layout.pos.row = 2, layout.pos.col=6:11, just="left"))

pushViewport(viewport(layout.pos.row = 3, layout.pos.col=1:7))
plot(pp_plot$plot, newpage=FALSE)
popViewport()     
pushViewport(viewport(layout.pos.row = 3, layout.pos.col=8))
grid.text("Notes: \n1. quo durius te exerces, eo facilius certabis\n2. Ursis fidimus\n3. audaces fortuna juvat \n", just=0)

dev.off()

我已经厌倦了正义的争论,但无济于事。

OK,基于以上,达到了我的要求。我需要使用负仓位:

png(filename = "test.png", width = 11, height = 8, units ="in", res=72)

grid.newpage()
pushViewport(top.vp)
print(london_map, vp = viewport(layout.pos.row = 2, layout.pos.col=1:5, just=c("left","top")))
print(london_terrain, vp = viewport(layout.pos.row = 2, layout.pos.col=6:11, just="left"))

pushViewport(viewport(layout.pos.row = 3, layout.pos.col=1:7))
plot(pp_plot$plot, newpage=FALSE, position=c(-0.18,0,0.82,1))
popViewport()     
pushViewport(viewport(layout.pos.row = 3, layout.pos.col=6))
grid.text("Notes: \n1. quo durius te exerces, eo facilius certabis\n2. Ursis fidimus\n3. audaces fortuna juvat \n", 
          x = 0.85, just = "left")

dev.off()