是否可以使用带有sf地图图的背景图像,并且还可以使用正在使用的坐标参考系统对图像进行转换?例如,下面的第一幅图使用NASA night lights image和EPSG:4326。第二个图像是EPSG:3035。数据点似乎已在CRS上正确绘制,但是背景图像未显示。
CRS EPSG 4326:似乎正确 CRS EPSG 3035:无背景图片 使用的代码:
# Download NASA night lights image
download.file("https://www.nasa.gov/specials/blackmarble/2016/globalmaps/
BlackMarble_2016_01deg.jpg",destfile = "BlackMarble_2016_01deg.jpg",mode = "wb")
# Load picture and render
earth <- readJPEG("BlackMarble_2016_01deg.jpg",native = TRUE)
earth <- rasterGrob(earth,interpolate = TRUE)
# Select crs as desired
crs.inuse = 4326 # WGS 84
crs.inuse = 3035 # ETRS89 / LAEA Europe
# Plot geoname localities with population >100k with ggplot
ggplot() +
annotation_custom(earth,xmin = -180,xmax = 180,ymin = -90,ymax = 90) +
geom_sf(data = popn.sf,aes(geometry=geometry),alpha = 0.4,size = 2,colour = "white") +
theme(panel.background = element_rect(fill = "#05050f",colour = "#05050f"),panel.grid.major = element_blank(),panel.grid.minor = element_blank(),axis.title = element_blank(),axis.text = element_blank(),axis.ticks.length = unit(0,"cm"),legend.position = "none") +
coord_sf(crs = st_crs(crs.inuse))