Concerning my last post, I successfully plotted the school districts on a national map using the library tmap. Below is my attempt to plot the map.
As you can see, this is far behind the reference (by Laura Bliss: Bloomberg CityLab, 2015) that I want to follow. I guess there might be something wrong when I used
st_make_valid()
. Thus, I ran the following code to see the reasons behind Error: Shape contains invalid polygons (please note that I used Alabama (al) as an example, and the responses from st_is_valid(..., reason = TRUE)
are 140 lines in total).
al <- map[map$STATEFP == "01", ]
st_is_valid(al, reason = TRUE)
[1] "Valid Geometry"
[2] "Valid Geometry"
[3] "Loop 2: Edge 750 has duplicate vertex with edge 811"
[4] "Loop 40: Edge 6246 has duplicate vertex with edge 6268"
[5] "Loop 37: Edge 9 has duplicate vertex with edge 66"
[6] "Loop 43: Edge 19 has duplicate vertex with edge 27"
[7] "Loop 12: Edge 680 has duplicate vertex with edge 693"
[8] "Loop 1: Edge 752 has duplicate vertex with edge 834"
[9] "Loop 30: Edge 142 has duplicate vertex with edge 154"
[10] "Valid Geometry"
[11] "Valid Geometry"
[12] "Loop 3: Edge 1619 has duplicate vertex with edge 1641"
[13] "Valid Geometry"
[14] "Loop 3: Edge 1533 has duplicate vertex with edge 1543"
[15] "Valid Geometry"
I am wondering if the dark areas on my map occurred because of st_make_valid()
. If so, how should I fix this map to get a similar result as my reference? Any advice/suggestions/resources to solve this problem would be appreciated!