Search code examples
rrasterr-sfterra

changing extent of SpatVector for better visualisation


library(geodata)
ct_shp <- geodata::gadm('USA', level = 0, path=".")        
plot(ct_shp) 

When I plot the USA, I get this.

enter image description here

Any raster I plot for US using this shapefile as a basemap becomes really small. The only solution I have is to crop out polygons greater than 100 degrees longitude so that I get a bigger map of US and I can plot any US specifc raster for more appealing maps. I wondered if there's anyone who faces such issue and how they have dealt with it.


Solution

  • In this case I would first simplify the geometries a bit (that speeds things up, but is otherwise not related to your question).

    library(geodata)
    usa <- geodata::gadm('USA', level = 0, path=".")        
    usa <- simplifyGeom(usa, 0.01)
    

    You can select the western hemisphere (or any other area) like this

    e <- ext(-180, -60, 11, 78)
    p <- crop(usa, e)
    

    Alternatively, you can use rotate to eastern hemisphere bit so that it connects to the western hemisphere. For that you need "terra" >= 1.6-21 (currently the development version, you can install it with install.packages('terra', repos='https://rspatial.r-universe.dev'))

    r <- rotate(usa, long=0, split=T)
    plot(r)
    

    enter image description here

    This is still not a great basemap for the USA. There is a lot of whitespace and Alaska is way too big for most purposes. I would either use an appropriate (conical) map projection, or cut, resize, and move Alaska and Hawaii, but that is quite involved.