How do I switch to a map that focuses on China rather than the default one installed in R?

I have used R to plot the world map and I want to switch to a map that is centered in the Pacific and dividing the Atlantic to make my data plot simpler.

But the default R set looks like this:

 map("world") 

      

R default set

And I want the map to be like this:

world map wanted

I tried the R worldmap help option "orientation". Although the help says that "the orientation is a vector c (latitude, longitude, rotation) describing where the map should be centered, and a clockwise rotation (in degrees) around that center." I still couldn't use it like the following command does it:

 map("world",orientation=c(35,104,0)) 

 Warning:
 In map("world", orientation = c(35, 104, 0)) :
 projection failed for some data

      

the result looks like this:

The R plotting odd map

The result is strange. So how can I get something correct as shown in Figure 2? Thank.

0


source to share


2 answers


Your example image appears to be centered around 0 lats, 150 lons. The following seems to roughly generate an example image for you:

library(maps)
map("world",orientation=c(90, 150,0), projection="mollweide", wrap=TRUE) 

      



For some reason, you feel like you need to add 90 to your longitude.

+4


source


This is a more complex solution, but a good educational exercise to get you started with SpatialPolygons.

library(maptools)
library(rgdal)
data(wrld_simpl) #The world as a SpatialPolygonsDataFrame
#To avoid the lines crossing the map after reprojection we need to cut the polygons at the new break:
w <- nowrapRecenter(wrld_simpl, offset = 180-150, avoidGEOS=TRUE)
#Then proceed with the reprojection (note the proj4 string for a mollweide projection with 150°E as the new center)
wrld_china <- spTransform(w, CRS("+proj=moll +lon_0=150"))
plot(wrld_china)

      



enter image description here

+1


source







All Articles