Use different center than the prime meridian in plotting a world map

后端 未结 3 1832
梦毁少年i
梦毁少年i 2020-11-28 06:48

I am overlaying a world map from the maps package onto a ggplot2 raster geometry. However, this raster is not centered on the prime meridian (0 deg

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 07:16

    This may be somewhat tricky but you can do by:

    mp1 <- fortify(map(fill=TRUE, plot=FALSE))
    mp2 <- mp1
    mp2$long <- mp2$long + 360
    mp2$group <- mp2$group + max(mp2$group) + 1
    mp <- rbind(mp1, mp2)
    ggplot(aes(x = long, y = lat, group = group), data = mp) + 
      geom_path() + 
      scale_x_continuous(limits = c(0, 360))
    

    enter image description here

    By this setup you can easily set the center (i.e., limits):

    ggplot(aes(x = long, y = lat, group = group), data = mp) + 
      geom_path() + 
      scale_x_continuous(limits = c(-100, 260))
    

    enter image description here

    UPDATED

    Here I put some explanations:

    The whole data looks like:

    ggplot(aes(x = long, y = lat, group = group), data = mp) + geom_path()
    

    enter image description here

    but by scale_x_continuous(limits = c(0, 360)), you can crop a subset of the region from 0 to 360 longitude.

    And in geom_path, the data of same group are connected. So if mp2$group <- mp2$group + max(mp2$group) + 1 is absent, it looks like: enter image description here

提交回复
热议问题