I have an sf polygon object and am wondering how can I draw contour lines based on the column values. What I want to realize is something like below (this map is credited to here).
My data look like below. Please download the data from here. I want to draw the contour lines based on column contour
. My polygons are identical to the example above. Any thoughts?
Simple feature collection with 6 features and 4 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -88.47322 ymin: 30.22113 xmax: -84.89089 ymax: 35.00802
Geodetic CRS: NAD83
STATE STASD_N STASD_A geometry contour
1 01 110 0110 MULTIPOLYGON (((-87.92697 3... 141
2 01 120 0120 MULTIPOLYGON (((-85.59516 3... 190
3 01 130 0130 MULTIPOLYGON (((-87.91345 3... 76
4 01 140 0140 MULTIPOLYGON (((-87.83804 3... 70
5 01 150 0150 MULTIPOLYGON (((-88.08681 3... 112
6 01 160 0160 MULTIPOLYGON (((-84.99523 3... 167
Here are what I have tried with tmap
. There is a tm_iso
function however it only accepts spatial lines. Thus I converted my polygons to lines with st_cast
. See the code below.
lines <- st_cast(asdsiso, 'MULTILINESTRING')
tm_shape(lines) + tm_iso(col = 'contour', text = 'contour')
Then I think probably I can aggregate the polygons. Thus I tried the code below. BUt the map is still the same except for the legend.
linesAgg <- linesAgg %>% group_by(contour2) %>%
summarise(contour2 = mean(contour2))
tm_shape(linesAgg) + tm_iso(col = 'contour2', text = 'contour2')
The map is still the same except for the legend.