0

I'm making a map of flood zones that ends up with additional lines I don't want. Here is the code:

tmap_mode("view")

tm_shape(floodplot) +
  tm_polygons(
    col = "Risk Level",
    alpha = 0.9,
    palette = colors)
  ) +
  tm_layout(
    title = "What is the risk of flooding in Robeson County?",
    legend.position = c("right", "top"),
    legend.text.size = 12
  ) +
  tm_style(style = "classic")

And here is the map: enter image description here

The horizontal and vertical lines are the census tracts, but I don't want them on this map. The floodplot data has a geometry column as well as a SHAPE_Leng and SHAPE_Area column, which I assume are causing the issue.

I tried using some arguments in tm_lines, but it didn't work. Doesn't actually seem like any of the lines after the polygons layer is changing the map, but I'm fine with that if I can get rid of the census tract lines.

As a temporary solution I set lwd = 0, but that of course removes all the lines. The person who showed me the data said something about dissolving the polygons, but I'm not sure how to do that.

Thank you!

taylorpot
  • 25
  • 4

2 Answers2

0

You should try to add and manipulate the function tm_grid() (see documentation) to your map code. It is hard to come with a solution if you don't share the data, but probably adding:

+ tm_grid(alpha = 1)

or:

+ tm_grid(lines = FALSE)

should work.

LuizZ
  • 945
  • 2
  • 11
  • 23
0

As for the dissolving: while it is difficult to make 100% certain without having a look at your data I suppose this should be doable via a dplyr::summarise() call; something along the lines of

library(dplyr)
library(sf)


floodplot <- floodplot %>%
   group_by(`Risk Level`) %>% 
   summarise()

You will find the technique explained here: https://www.jla-data.net/eng/merging-geometry-of-sf-objects-in-r/

Jindra Lacko
  • 7,814
  • 3
  • 22
  • 44