Why does coord_map produce a weird output?

前端 未结 3 2107
梦毁少年i
梦毁少年i 2021-02-20 02:19

I\'m trying to draw a world map using ggplot. My code is in my gist file. The output is correct when I don\'t use coord_map but very strange when I use

相关标签:
3条回答
  • 2021-02-20 02:58

    Another solution is to use wrld_simpl from maptools instead, but it retains issues with Antarctica.

    require(maptools)
    require(ggmap)
    
    md <- map_data("world2")
    data(wrld_simpl)
    ggplot(wrld_simpl, aes(group = group, x = long, y = lat)) +
      geom_map() +
      coord_map()
    

    Imgur

    0 讨论(0)
  • 2021-02-20 03:12

    I'm sure that is quite late but the same problem is still happening in ggplot.

    If you're trying to zoom-in use the following approach.

    ggplot()+...+xlim(c(-100, -25))+ ylim(c(-60, 20))
    

    Good luck!

    0 讨论(0)
  • 2021-02-20 03:17

    I had a similar problem before, due to longitude values outside the range [-180,180]. In your example the data do not have this problem but my trick seems to work also here. In my case I just used 'xlim' to exclude the problematic data.

    This solution seems to work in your case also (I used the code from your gist):

    map+coord_map(xlim=c(-180,180))
    

    It produces the following map:

    enter image description here

    There is still a problem with Antarctica, you can also consider clipping it too if you don't need this area:

    map+coord_map(xlim=c(-180,180), ylim=c(-60, 90))
    

    enter image description here

    0 讨论(0)
提交回复
热议问题