我正在尝试使用 patchwork 包中的 inset_element() 函数将小地图嵌入到大地图上。
尝试插入地图时出现此错误:
Error in seq.default(design$t[i], design$b[i]) :
'from' must be a finite number
这是一个例子:
library(patchwork)
library(sf)
library(ggplot2)
library(rnaturalearth)
world <- rnaturalearth::ne_countries(scale='medium',returnclass = 'sf')
p1 <- ggplot()+
geom_sf(data= world)
p2 <- ggplot() +
geom_point(data = iris, aes(x= Petal.Width, y = Petal.Length))
# 2 maps = fail
p1 + inset_element(p1, left =0.75, right =0.95, bottom = 0.75, top =0.95)
# 1 map as "main" = success
p1 + inset_element(p2, left =0.75, right =0.95, bottom = 0.75, top =0.95)
# 1 map as "inset" = fail
p2 + inset_element(p1, left =0.75, right =0.95, bottom = 0.75, top =0.95)
packageVersion("patchwork")