Reputation: 455
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.
Upvotes: 3
Views: 1932
Reputation: 94162
You might want to read the R Spatial Task View, and also use package:maptools to read and plot Shapefiles. Then you can either use package:rgeos to dissolve boundaries of a county shapefile or get a county and a state shapefile and plot them separately.
The old 'maps' package is a bit limited.
Upvotes: 2
Reputation: 22588
map.poly()
with as.polygon=FALSE
, and then plot this with lines()
. 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)
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...
Upvotes: 2