Reputation: 51
I'm trying to use annotate_map_tile() from ggplot2 to add a basemap to my ggplot maps. I've had success using it with geom_sf() layers, but it is throwing an error with a single point loaded through geom_point().
Here's the code:
site<- data.frame(longitude = -75.144353, latitude = 39.917631)
ggplot()+
annotation_map_tile("cartolight")+
geom_point(data = site, aes(x = longitude, y = latitude), size = 5)
The error reads "Error in grid.Call.graphics(C_raster, x$raster, x$x, x$y, x$width, x$height, : cannot allocate memory block of size 67108864 Tb". Any help?
Upvotes: 3
Views: 3191
Reputation: 432
If you convert your point to an sf
object and then plot it using geom_sf()
it seems to work just fine. One reason your code is failing is that annotation_map_tile()
doesn't know which tiles to pull because you haven't specified any data for it.
library(tidyverse)
library(sf)
library(ggspatial)
site <- data.frame(longitude = -75.144353, latitude = 39.917631) %>%
st_as_sf(coords = c("longitude", "latitude"), crs = 4326)
ggplot(site) +
annotation_map_tile("cartolight") +
geom_sf(size = 5)
Upvotes: 4