例子:
我想将由此代码生成的两个tmap图并排放置。
library(tmap)
library(gridExtra)
data(World)
plot1=
tm_shape(World, projection = "merc") +
tm_layout("", inner.margins=c(-1.72, -2.05, -0.75, -1.56)) +
tm_borders(alpha = 0.3, lwd=2)
plot2=
tm_shape(World, projection = "merc") +
tm_layout("", inner.margins=c(-1.72, -2.05, -0.75, -1.56)) +
tm_borders(alpha = 0.3, lwd=2)
问题:
我无法将两个图表并排放置。我尝试了:
grid.arrange(plot1, plot2)
报错:Error in arrangeGrob(..., as.table = as.table, clip = clip, main = main, : input must be grob!
。我认为这应该可以使用gridExtra来解决,因为tmap似乎是基于grid graphics system
构建的。
此外,par(mfrow=c(1,2))
也不起作用,因为它只显示一个图表(我猜测这与tmap
绘图不遵循base graphics system
有关)。
问题:
如何将plot1
和plot2
对象并排显示(ncol=2
)?
更新:
关于提出的基于网格的解决方案,我得到的是重叠的图表,而不是两列排列的图表。
> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
locale:
[1] de_DE.UTF-8/de_DE.UTF-8/de_DE.UTF-8/C/de_DE.UTF-8/de_DE.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] tmap_1.0 dplyr_0.4.3 sp_1.1-1
loaded via a namespace (and not attached):
[1] assertthat_0.1 class_7.3-11 classInt_0.1-23 colorspace_1.2-6 DBI_0.3.1 digest_0.6.8 e1071_1.6-4 ggplot2_1.0.1
[9] grid_3.1.2 gridBase_0.4-7 gtable_0.1.2 lattice_0.20-29 magrittr_1.5 MASS_7.3-35 munsell_0.4.2 parallel_3.1.2
[17] plyr_1.8.3 proto_0.3-10 R6_2.1.1 raster_2.3-40 RColorBrewer_1.1-2 Rcpp_0.12.2 reshape2_1.4.1 rgdal_0.8-16
[25] rgeos_0.3-11 scales_0.3.0 stringi_1.0-1 stringr_1.0.0 tools_3.1.2
+tm_facets(ncol=2)
手动设置它们。 - Martijn TennekessessionInfo()
吗? - Martijn Tennekestmap
1.2已经在CRAN上发布了两周,其中视口错误已经得到修复。 - Martijn Tennekes