Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine counties in geographic data

Tags:

r

maps

geospatial

I would like to represent multiple counties in TN state as a single region using a common color fill. I can do that with the code below:

library(maps)
map("state", "tennessee", fill = TRUE, col="white", names = TRUE, plot = TRUE)
co <- map("county",region = c("tennessee,williamson","tennessee,davidson",
                         "tennessee,wilson","tennessee,cheatham"),
       col = "red", bg = "blue", fill = TRUE, plot = FALSE)
polygon(co$x, co$y, col = "yellow", border = "black")

But the black borders are drawn inside my region of interest. Is there a way to define the polygon function such that common county borders are not drawn in black?

Thank you.

like image 650
user1106711 Avatar asked Mar 04 '26 02:03

user1106711


1 Answers

  • To get the outside border of the whole ROI, you need a call to map.poly() with as.polygon=FALSE, and then plot this with lines().
  • To get the solid inside fill you need a call to map.poly() with as.polygon=TRUE and then plot this with polygon() and border=FALSE.

You can see this if you look through the code of map by just entering it at the command line and hitting enter.

Here is the code I used to get what you want:

map("state","tennessee",fill=T,col="white",names=T,plot=T)
coords = map.poly("county",region=c("tennessee,williamson","tennessee,davidson","tennessee,wilson","tennessee,cheatham"), boundary=T, interior=F, fill=F, as.polygon=T)
polygon(coords, col='red', border=F)
map("county",region=c("tennessee,williamson","tennessee,davidson","tennessee,wilson","tennessee,cheatham"),fill=F,interior=F,add=T)

enter image description here

From reading ?map, I thought simply doing something like map(..., interior=F, fill=T, col='red') would work, but this doesn't seem to do it. Could be a bug, but I haven't played with this package enough to know for sure...

like image 97
John Colby Avatar answered Mar 05 '26 14:03

John Colby



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!