How to plot grid plots on a same page?

﹥>﹥吖頭↗ 提交于 2019-11-29 08:42:34

Thanks for your question. The output of tmPlot is indeed not a saved plot.

In the next update I will add argument vp, by which a viewport can be specified to draw in. Only if it is not specified, grid.newpage is called.

UPDATE: You could check and test the development version at https://github.com/mtennekes/treemap

To apply the example of Bryan Hanson:

vplayout <- function(x, y) viewport(layout.pos.row = x, layout.pos.col = y)
grid.newpage()
pushViewport(viewport(layout = grid.layout(1, 2)))
tmPlot(GNI2010,
  index="continent",
  vSize="population",
  vColor="GNI",
  type="value",
  vp = vplayout(1,1))
tmPlot(GNI2010,
  index=c("continent", "iso3"),
  vSize="population",
  vColor="GNI",
  type="value",
  vp = vplayout(1,2))

Here's an approach that is very flexible for any grid graphics:

vplayout <- function(x, y) viewport(layout.pos.row = x, layout.pos.col = y)
grid.newpage()
pushViewport(viewport(layout = grid.layout(1, 2)))
print(a, vp = vplayout(1,1))
print(b, vp = vplayout(1,2))

Where a and b are your saved plot objects. So test each plot individually ahead of time, save them as a, b, ... then plot them as above.

Oh, and if tmPlot always does grid.newpage then check to see if it has a has new.page argument which you can set to FALSE, or make a copy of the function and comment out the newpage.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!