Closed seaCatKim closed 5 months ago
Having the same issue with basemap_gglayer()
trying to plot esri world_imagery. Looks like there are NA values in the SpatRaster object that basemap()
generates, which gg_raster()
is therefore unable to plot. The same map_type and ext were working fine for me two days ago, so presumably this has happened because the esri world_imagery data has been updated in some way, and the issue may well correct itself if it's updated again? It would be helpful though if basemap()
could automatically convert NA values to zero e.g. map[is.na(map)]<-0
when class = "ggplot"
or "gglayer"
.
This has also broken some of my workflows wit esri layers and osm topographic, osm stamen still seems to work fine
I'm also loving basemaps
, but am having the same problem. None of the map_service='osm' options are working for me.
In case anyone comes looking for a workaround, you can first download the basemap as a raster, then plot that in ggplot
:
library(ggplot2)
library(basemaps)
library(raster)
data(ext)
m1 <- basemap_gglayer(ext, "esri", "world_imagery", map_res=1) # low res/blurry
ggplot() +
m1 +
scale_fill_identity() +
coord_sf()
m2 <- basemap_raster(ext, "esri", "world_imagery", map_res=1) # hi res
m2_xy <- as.data.frame(m2, xy=TRUE)
ggplot() +
geom_raster(data=m2_xy,
aes(x=x, y=y,
fill=rgb(red=red, green=green, blue=blue, maxColorValue=255))) +
scale_fill_identity(guide="none") +
coord_sf()
@irhoppe's solution worked for me for 2-3 days, but has now broken as well! The basemap_raster()
call now produces some NAs, so I suppose the only solution is to manually remove NAs (rationale here).
This should be solved with PR #20 by @robertomrosati.
@seaCatKim on my side, your code now runs without the error you reported. Please try whether the error persists after installing the most recent version 0.0.6 of basemaps
from CRAN. Thanks!
Please reopen if this issue can be still encountered with the latest CRAN
release of basemaps
.
Loving the basemaps package!
Running into an error when I try and use
basemap_ggplot()
for a reef I am trying to map. From memory, it was working fine until I read in a saved geotif (basemap_geotif()
) with {stars} and then plotted the raster withgeom_stars()
. Looks like the values have changed from 0:1 to 0:255 potentially?? color intensity is NA?Thanks in advance!
Created on 2023-02-10 with reprex v2.0.2