Concerning my 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!
CodePudding user response:
As Chris pointed out, the darker areas are due to the density of the polygons you're mapping. You can adjust the border size with the lwd
argument in tmap
's functions.
Since the polygons are so dense, and you're filling them according to the data, you can probably go very low with the lwd
argument. Default is 1.
Examples:
library(tmap)
library(sf)
nc <- st_read(system.file("shape/nc.shp", package="sf"))
tm_shape(nc) tm_polygons('BIR74',lwd = 0)
tm_shape(nc) tm_polygons('BIR74',lwd = 5)
Created on 2022-04-11 by the reprex package (v2.0.1)