I'm trying to make a small map embedded on a large map using the inset_element() function from the patchwork package.
I get this error when trying to inset a map:
Error in seq.default(design$t[i], design$b[i]) :
'from' must be a finite number
here is an example:
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")
inset_element
seems to be a new feature in patchwork, and I think you have discovered a bug which has also affected other users. The error is thrown in this line inset_panel_dimensions
, which is only called when you try to print (rather than create) this patchwork object:However, we can work round this error for now by setting the layout height and width for the
patches
object to 1:I have referenced this answer in the patchwork github issues thread mentioned above.