library(sf)#"s2" is an enhancement of the "sf" package#It allows one to complete spatial operations with data that is in geographic coordinate system (the coordinates are in degrees)#However, having it enables will take much longer computation timesf_use_s2(FALSE)library(ggplot2)#Step1: Read country shapeusa_cntry <-st_read(dsn="./data/gadm41_USA_shp/gadm41_USA_0.shp", quiet =TRUE)#Step2: Simplify linesusa_cntry<-st_simplify(usa_cntry, dTolerance =0.05)#Define zoommin_lon_x_us<-(-130)max_lon_x_us<-(-57)min_lat_y_us<-(26)max_lat_y_us<-(53)#Mapfig<-ggplot()+geom_sf(data=usa_cntry, linewidth =0.3, fill =NA)+theme_bw()+coord_sf(xlim =c(min_lon_x_us-3, max_lon_x_us+3), ylim =c(min_lat_y_us-3, max_lat_y_us+3))
Mapping the US USA_0
fig
Mapping the US USA_0
Let us examine what the dataframe looks like
head(usa_cntry, 2)
Simple feature collection with 1 feature and 2 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -178.9911 ymin: 18.91028 xmax: 179.7485 ymax: 71.33542
Geodetic CRS: WGS 84
GID_0 COUNTRY geometry
1 USA United States MULTIPOLYGON (((179.6461 52...
Mapping the US USA_0
This is how we turn the sf object into a simple dataframe