The answer by @thelatemail is the best and simplest solution I've seen to this problem. To make it more universal, though, it is better to remove the polygons by name. This is because depending on the limits you give your first call to map(), the indices of the polygon names can be different.
library(maps)
library(mapproj)
library(mapdata)
mapnames <- map("world2Hires", xlim=c(120, 260), ylim=c(-60, 40),
fill=TRUE, plot=FALSE)
mapnames2 <- map("world2Hires", xlim=c(100, 200), ylim=c(-20, 60),
fill=TRUE, plot=FALSE)
mapnames$names[10]
[1] "Mali"
mapnames2$names[10]
[1] "Thailand"
There are 8 countries that are intersected by the Prime Meridian: United Kingdom, France, Spain, Algeria, Mali, Burkina Faso, Ghana, and Togo. By matching these country names with mapnames$names
, you can remove the polygons regardless of your original extent:
remove <- c("UK:Great Britain", "France", "Spain", "Algeria", "Mali",
"Burkina Faso", "Ghana", "Togo")
map("world2Hires", regions=mapnames$names[!(mapnames$names %in% remove)],
xlim=c(120, 260),
ylim=c(-60, 40),
boundary=TRUE,
interior=TRUE,
fill=TRUE
)
map.axes()
You could also use grepl() but because polygons are named heirarchically, you may remove some sub-polygons of the nations in question. For example, mapnames$names[grepl("UK", mapnames$names)]
returns 34 matches.
I would have suggested this as an edit, but I don't have privileges yet.