Closed richardvogg closed 3 years ago
I seem to be having same issue with {sf}
, reprex:
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(patchwork)
nc <- system.file("shape", package = "sf") %>%
st_read("nc")
#> Reading layer `nc' from data source `C:\Program Files\R\R-4.0.3\library\sf\shape' using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> geometry type: MULTIPOLYGON
#> dimension: XY
#> bbox: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> geographic CRS: NAD27
p <- ggplot(nc) + geom_sf()
p + inset_element(p, 0, 0, 0.5, 0.5)
#> Error in seq.default(design$t[i], design$b[i]): 'from' must be a finite number
Thanks for the great inset update @thomasp85. Its a great idea and will simplify insets maps greatly. Unfortunately I can confirm this doesn't work with an sf plot. I have my own code, but I have also tested @tomjemmett reprex above. Both give the same error #> Error in seq.default(design$t[i], design$b[i]): 'from' must be a finite number
Related - see this stack overflow post which tracks this bug to set_panel_dimensions
and shows a quick & dirty workaround
I really, really like the new inset_element() function in patchwork.
This is not a big issue, but I noticed that when I am using coord_quickmap() in a plot, inset_element() does not work.
Small example:
`library(ggplot2)
test <- ggplot()+borders(regions="france")+coord_quickmap() test + inset_element(test,0.1,0.1,0.5,0.5) `
Error in seq.default(design$t[i], design$b[i]) : 'from' must be a finite number
The same without coord_quickmap() works.