Map in ggplot2 render / error display?

As you can see below, on maps created with ggplots, there is a strange display problem. The same problem occurs with any projection.

enter image description here

Here is the code: Only packages mapsandggplot2

  mapWorld <- borders("world", colour="gray50", fill="black")
    ggplot() + mapWorld +
      coord_map("mercator") +
      ylim(-90,90)
+4
source share
2 answers

Apparently, the problem is caused by polygons crossing the 0 coordinate, the place where the world merges. R dont know how to close these polygons and design them around the world.

This method recreates the polygons and prevents them from crossing the 0 coordinate (xlim and ylim). It works with any kind of projection.

require(ggplot2)
require(PBSmapping)
require(data.table)

mapWorld <- map_data("world")
setnames(mapWorld, c("X","Y","PID","POS","region","subregion"))
worldmap = clipPolys(mapWorld, xlim=xlim,ylim=ylim, keepExtra=TRUE)
ggplot() + geom_polygon(data = mapWorld, aes(X,Y,group=PID))
+1
source

why do you need to use?

ggplot() + mapWorld +
  coord_map("mercator") +
  ylim(-90,90)

if u uses only

ggplot() + mapWorld

It works great

+1
source

Source: https://habr.com/ru/post/1589088/


All Articles