ggspatial icon indicating copy to clipboard operation
ggspatial copied to clipboard

Error when using annotation_map_tile() layer. Package example plot returns error

Open EllaSantanaPropper opened this issue 10 months ago • 1 comments

I noticed that the plots are no longer working if the layer annotation_map_tile is included in the code. To make sure it wasn't my data, I checked with the code example given on the ggspatial homepage (https://paleolimbot.github.io/ggspatial/).

The following code returns this error: Error in annotation_map_tile(): ! Problem while converting geom to grob. ℹ Error occurred in the 1st layer. Caused by error in loadNamespace(): ! there is no package called 'prettymapr'

# Code from ggspatial package homepage demonstrating how it works

library(ggplot2)
library(ggspatial)
load_longlake_data()

ggplot() +
  # loads background map tiles from a tile source
  annotation_map_tile(zoomin = -1) +
  
  # annotation_spatial() layers don't train the scales, so data stays central
  annotation_spatial(longlake_roadsdf, size = 2, col = "black") +
  annotation_spatial(longlake_roadsdf, size = 1.6, col = "white") +
  
  # raster layers train scales and get projected automatically
  layer_spatial(longlake_depth_raster, aes(colour = after_stat(band1))) +
  # make no data values transparent
  scale_fill_viridis_c(na.value = NA) +
  
  # layer_spatial trains the scales
  layer_spatial(longlake_depthdf, aes(fill = DEPTH_M)) +
  
  # spatial-aware automagic scale bar
  annotation_scale(location = "tl") +
  
  # spatial-aware automagic north arrow
  annotation_north_arrow(location = "br", which_north = "true")

Image

However, when I comment out the annotation_map_tile() layer, the plot does run, but obviously does not include a basemap:

ggplot() +
  # loads background map tiles from a tile source
  #annotation_map_tile(zoomin = -1) +
  
  # annotation_spatial() layers don't train the scales, so data stays central
  annotation_spatial(longlake_roadsdf, size = 2, col = "black") +
  annotation_spatial(longlake_roadsdf, size = 1.6, col = "white") +
  
  # raster layers train scales and get projected automatically
  layer_spatial(longlake_depth_raster, aes(colour = after_stat(band1))) +
  # make no data values transparent
  scale_fill_viridis_c(na.value = NA) +
  
  # layer_spatial trains the scales
  layer_spatial(longlake_depthdf, aes(fill = DEPTH_M)) +
  
  # spatial-aware automagic scale bar
  annotation_scale(location = "tl") +
  
  # spatial-aware automagic north arrow
  annotation_north_arrow(location = "br", which_north = "true")

Image

I am using R version 4.4.2 "Pile of Leaves" and ggspatial 1.1.9

EllaSantanaPropper avatar Feb 07 '25 01:02 EllaSantanaPropper

I also encountered this. The solution is to install the prettymapr package. Maybe it should be mandatory to install and listed in "Imports" in the DESCRIPTION?

library("ggplot2")
library("ggspatial")
load_longlake_data(which = "longlake_waterdf")

ggplot() +
  annotation_map_tile(zoom = 1) +
  geom_sf(data = longlake_waterdf)
#> Error in `annotation_map_tile()`:
#> ! Problem while converting geom to grob.
#> ℹ Error occurred in the 1st layer.
#> Caused by error in `loadNamespace()`:
#> ! there is no package called ‘prettymapr’

kadyb avatar May 24 '25 14:05 kadyb