Pacific Country Map with Filled Countries

I am trying to build a map of the Pacific Ocean using World2Hires in the R mapproj library, but there is a strange glitch when I try to populate countries. How to fix it?

library(maps) library(mapproj) library(mapdata) map("world2Hires", xlim=c(120, 260), ylim=c(-60, 40), boundary=TRUE, interior=TRUE, fill=TRUE, col="gray30", ) map.axes() 

Here's the conclusion:

Broken map image

+7
r map
source share
2 answers

The problem is with a small subset of the areas that cause wrapping. From some trial and error, preserving the original map call of type mapnames <- map(...) , and then passing subsets of this list to the regions= argument on a new call, I could avoid wrapping the fillings. For example:.

 library(maps) library(mapproj) library(mapdata) map("world2Hires", regions=mapnames$names[c(1:7,14:641)], xlim=c(120, 260), ylim=c(-60, 40), boundary=TRUE, interior=TRUE, fill=TRUE ) map.axes() 

enter image description here

As for a more thorough or sensible decision, to prevent this, I'm at a standstill. Playing with the wrap= option helps nothing, as well as for other options. As a note, this problem does not appear using the "world" database, but only appears for "world2" and "world2Hires" .

+7
source share

@Thelatemail's answer is the best and easiest solution I've seen in this issue. However, to make it more universal, it is better to delete polygons by name. This is because, depending on the limitations that you give your first call to map (), the polygon name indices may 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 intersect with the main meridian: the United Kingdom, France, Spain, Algeria, Mali, Burkina Faso, Ghana and Togo. mapnames$names country names with mapnames$names , you can delete polygons regardless of the initial length:

 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 can also use grepl (), but since polygons are called hierarchically, you can delete some sub-polygons of the respective countries. For example, mapnames$names[grepl("UK", mapnames$names)] returns 34 matches.

I would suggest how to edit it, but I do not have privileges yet.

+5
source share

All Articles