Open
Description
In the reprex below, adding annotation_map_tile() as the only layer in a ggplot gives the error "Scale limits cannot be mapped onto spatial coordinates", suggesting setting lims_method = "geometry_bbox"
or default_crs = NULL
.
However, both of those options give errors too. How is this supposed to work? For my purposes it is okay to always include the geom_sf(), but I'm reporting this in case it is actually a bug.
The point
object was made by dput()
ing the first row of my spatial data frame. I do not have the expertise to check if it is malformed in some way, but hopefully someone else can check.
library(ggplot2)
point <- structure(list(id = structure(1L, levels = c("fox_12", "fox_13",
"fox_14", "fox_15", "fox_16", "fox_19", "fox_20", "fox_21", "fox_22",
"fox_23", "fox_24", "fox_25", "fox_6", "fox_7", "fox_9"), class = "factor"),
datetime = structure(1532720345, class = c("POSIXct", "POSIXt"
), tzone = "GMT"), geometry = structure(list(structure(c(10.7616530429933,
59.6799649715049), class = c("XY", "POINT", "sfg"))), class = c("sfc_POINT",
"sfc"), precision = 0, bbox = structure(c(xmin = 10.7616530429933,
ymin = 59.6799649715049, xmax = 10.7616530429933, ymax = 59.6799649715049
), class = "bbox"), crs = structure(list(input = "EPSG:4326",
wkt = "GEOGCRS[\"WGS 84\",\n DATUM[\"World Geodetic System 1984\",\n ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n LENGTHUNIT[\"metre\",1]]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n CS[ellipsoidal,2],\n AXIS[\"geodetic latitude (Lat)\",north,\n ORDER[1],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n AXIS[\"geodetic longitude (Lon)\",east,\n ORDER[2],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n USAGE[\n SCOPE[\"Horizontal component of 3D system.\"],\n AREA[\"World.\"],\n BBOX[-90,-180,90,180]],\n ID[\"EPSG\",4326]]"), class = "crs"), n_empty = 0L)), sf_column = "geometry", agr = structure(c(id = NA_integer_,
datetime = NA_integer_), levels = c("constant", "aggregate",
"identity"), class = "factor"), row.names = "1", class = c("sf",
"data.frame"))
# This works
ggplot(data = point) + ggspatial::annotation_map_tile() + geom_sf()
#> Loading required namespace: raster
#> Zoom: 11
#> Fetching 4 missing tiles
#> | | | 0% | |================== | 25% | |=================================== | 50% | |==================================================== | 75% | |======================================================================| 100%
#> ...complete!
# These fail
ggplot(data = point) + ggspatial::annotation_map_tile()
#> Error in `calc_limits_bbox()`:
#> ! Scale limits cannot be mapped onto spatial coordinates in
#> `coord_sf()`.
#> ℹ Consider setting `lims_method = "geometry_bbox"` or `default_crs = NULL`.
ggplot(data = point) + ggspatial::annotation_map_tile() + coord_sf(lims_method = "geometry_bbox")
#> Warning in min(x): no non-missing arguments to min; returning Inf
#> Warning in max(x): no non-missing arguments to max; returning -Inf
#> Warning in min(x): no non-missing arguments to min; returning Inf
#> Warning in max(x): no non-missing arguments to max; returning -Inf
#> Error in `ggspatial::annotation_map_tile()`:
#> ! Problem while converting geom to grob.
#> ℹ Error occurred in the 1st layer.
#> Caused by error in `seq.default()`:
#> ! 'from' must be a finite number
ggplot(data = point) + ggspatial::annotation_map_tile() + coord_sf(default_crs = NULL)
#> Error in `calc_limits_bbox()`:
#> ! Scale limits cannot be mapped onto spatial coordinates in
#> `coord_sf()`.
#> ℹ Consider setting `lims_method = "geometry_bbox"` or `default_crs = NULL`.
Created on 2024-10-05 with reprex v2.1.1
Metadata
Metadata
Assignees
Labels
No labels
Activity