As always, all contributed packages must first be installed into the R library with install.packages(), also accessed from the RStudio Tools menu. Then, accessed by retrieving them from the library with the library() function.
Simple feature collection with 6 features and 3 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -179.1435 ymin: 30.22362 xmax: 179.7809 ymax: 71.4125
Geodetic CRS: WGS 84
name postal Gini geometry
1 Alabama AL 0.4783 MULTIPOLYGON (((-87.41958 3...
2 Alaska AK 0.4333 MULTIPOLYGON (((-141.0056 6...
3 Arizona AZ 0.4624 MULTIPOLYGON (((-111.0063 3...
4 Arkansas AR 0.4807 MULTIPOLYGON (((-90.30422 3...
5 California CA 0.4887 MULTIPOLYGON (((-114.7243 3...
6 Colorado CO 0.4576 MULTIPOLYGON (((-109.0463 4...
Create the Maps
To show a map at appropriate scale, map only the contiguous states. So, remove Alaska and Hawaii from the sf data frame. Including them often changes the bounding box and can shrink the visible map.
Plot with default blue sequential scale. Set the fill color of each state according to its Gini index, creating a choropleth map. Accomplish the choropleth map with one line of ggplot2 code via the geom_sf() function that accesses our simple features data file: states48_sf.