我正在尝试使用cowplot::plot_grid将由tmap制作的地图test1与ggplot2制作的绘图test2组合起来。
library(ggplot2)
library(tmap)
library(cowplot)
library(ggplotify)
test2 <-ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + geom_point()
data("World")
test1 <- tm_shape(World) + tm_polygons("HPI")
plot_grid(test1,test2)
tmap似乎与cowplot不兼容:
"在as_grob.default(plot)中: 无法将tmap类对象转换为grob"
使用时出现相同问题。
tmap::tmap_arrange(test1,test2)
"tmap_arrange(test1, test2)中出现错误: 并非所有参数都是tmap对象"
我还尝试使用"as.grob"等函数将tmap转换为ggplotify对象,
test3 <- as.grob(test1)
但是没有成功。
"UseMethod("as.grob")出错: 对于类为“tmap”的对象,没有适用的方法"as.grob"
有什么建议吗?
谢谢!