R map - poor representation of land borders Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How to assign colors to categorical variables in ggplot2 that have stable mapping?How to reduce white space margins of world mapHow to shift a world Map so it is centered at the pacific ocean?R help: mapping - interpolate and contoursError in plotting data on USA mapSubscript a title in a Graph (ggplot2) with label of another fileUsing ggplot to plot a map from a matrixHow to properly plot projected gridded data in ggplot2?US border line is not added to geom_map maps of dispersed US regionsRemoving axis labelling for one geom when multiple geoms are present

Did John Wesley plagiarize Matthew Henry...?

First paper to introduce the "principal-agent problem"

What did Turing mean when saying that "machines cannot give rise to surprises" is due to a fallacy?

calculator's angle answer for trig ratios that can work in more than 1 quadrant on the unit circle

How to infer difference of population proportion between two groups when proportion is small?

How to make triangles with rounded sides and corners? (squircle with 3 sides)

Why are current probes so expensive?

What is "Lambda" in Heston's original paper on stochastic volatility models?

Is this Kuo-toa homebrew race balanced?

What does 丫 mean? 丫是什么意思?

How to achieve cat-like agility?

Diophantine equation 3^a+1=3^b+5^c

Noise in Eigenvalues plot

Pointing to problems without suggesting solutions

Marquee sign letters

3D Masyu - A Die

Twin's vs. Twins'

Short story about astronauts fertilizing soil with their own bodies

What is a more techy Technical Writer job title that isn't cutesy or confusing?

Problem with display of presentation

Why can't fire hurt Daenerys but it did to Jon Snow in season 1?

Fit odd number of triplets in a measure?

Is the time—manner—place ordering of adverbials an oversimplification?

Does the Rock Gnome trait Artificer's Lore apply when you aren't proficient in History?



R map - poor representation of land borders



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How to assign colors to categorical variables in ggplot2 that have stable mapping?How to reduce white space margins of world mapHow to shift a world Map so it is centered at the pacific ocean?R help: mapping - interpolate and contoursError in plotting data on USA mapSubscript a title in a Graph (ggplot2) with label of another fileUsing ggplot to plot a map from a matrixHow to properly plot projected gridded data in ggplot2?US border line is not added to geom_map maps of dispersed US regionsRemoving axis labelling for one geom when multiple geoms are present



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















I map the southern part of the South hemisphere. My issue is Australia which has poorly drawn borders.



My data :



library("maptools")
library("ggplot2")
library("tidyverse")

ylim_map <- c(-90, -30)
xlim_map <- c(-180, 180)
world <- maps::map("world", fill=TRUE, plot=FALSE, ylim = ylim_map)


Convert data in correct format for ggplot :



IDs <- sapply(strsplit(world$names, ":"), function(x) x[1])
world <- map2SpatialPolygons(world, IDs = IDs,
proj4string = CRS("+proj=longlat +datum=WGS84"))
world_map <- fortify(world)
world_map <- world_map[which(between(world_map$lat, ylim_map[1], ylim_map[2]) &
between(world_map$lon, xlim_map[1], xlim_map[2])),]


And my plot :



ggplot() +

coord_map("orthographic", orientation = c(-90, 0, 0),
xlim = xlim_map, ylim = c(ylim_map[1], ylim_map[2] + 10)) +

geom_map(data = world_map, map = world_map,
aes(x = long, y = lat, map_id = id), fill = "black") +

geom_text(aes(x = 180, y = ylim_map[2]+5, label = "180°E"), color = "black") +
geom_text(aes(x = 90, y = ylim_map[2]+5, label = "90°E"), angle = -90, color = "black") +
geom_text(aes(x = 0, y = ylim_map[2]+5, label = "0°"), color = "black") +
geom_text(aes(x = -90, y = ylim_map[2]+5, label = "90°W"), angle = 90, color = "black") +

labs(y = "", x = "") +

# Theme
theme(text = element_text(size = 20),
panel.background = element_blank(),
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.line = element_blank(),
aspect.ratio = 1)


enter image description here










share|improve this question






























    2















    I map the southern part of the South hemisphere. My issue is Australia which has poorly drawn borders.



    My data :



    library("maptools")
    library("ggplot2")
    library("tidyverse")

    ylim_map <- c(-90, -30)
    xlim_map <- c(-180, 180)
    world <- maps::map("world", fill=TRUE, plot=FALSE, ylim = ylim_map)


    Convert data in correct format for ggplot :



    IDs <- sapply(strsplit(world$names, ":"), function(x) x[1])
    world <- map2SpatialPolygons(world, IDs = IDs,
    proj4string = CRS("+proj=longlat +datum=WGS84"))
    world_map <- fortify(world)
    world_map <- world_map[which(between(world_map$lat, ylim_map[1], ylim_map[2]) &
    between(world_map$lon, xlim_map[1], xlim_map[2])),]


    And my plot :



    ggplot() +

    coord_map("orthographic", orientation = c(-90, 0, 0),
    xlim = xlim_map, ylim = c(ylim_map[1], ylim_map[2] + 10)) +

    geom_map(data = world_map, map = world_map,
    aes(x = long, y = lat, map_id = id), fill = "black") +

    geom_text(aes(x = 180, y = ylim_map[2]+5, label = "180°E"), color = "black") +
    geom_text(aes(x = 90, y = ylim_map[2]+5, label = "90°E"), angle = -90, color = "black") +
    geom_text(aes(x = 0, y = ylim_map[2]+5, label = "0°"), color = "black") +
    geom_text(aes(x = -90, y = ylim_map[2]+5, label = "90°W"), angle = 90, color = "black") +

    labs(y = "", x = "") +

    # Theme
    theme(text = element_text(size = 20),
    panel.background = element_blank(),
    axis.title = element_blank(),
    axis.text = element_blank(),
    axis.ticks = element_blank(),
    axis.line = element_blank(),
    aspect.ratio = 1)


    enter image description here










    share|improve this question


























      2












      2








      2


      2






      I map the southern part of the South hemisphere. My issue is Australia which has poorly drawn borders.



      My data :



      library("maptools")
      library("ggplot2")
      library("tidyverse")

      ylim_map <- c(-90, -30)
      xlim_map <- c(-180, 180)
      world <- maps::map("world", fill=TRUE, plot=FALSE, ylim = ylim_map)


      Convert data in correct format for ggplot :



      IDs <- sapply(strsplit(world$names, ":"), function(x) x[1])
      world <- map2SpatialPolygons(world, IDs = IDs,
      proj4string = CRS("+proj=longlat +datum=WGS84"))
      world_map <- fortify(world)
      world_map <- world_map[which(between(world_map$lat, ylim_map[1], ylim_map[2]) &
      between(world_map$lon, xlim_map[1], xlim_map[2])),]


      And my plot :



      ggplot() +

      coord_map("orthographic", orientation = c(-90, 0, 0),
      xlim = xlim_map, ylim = c(ylim_map[1], ylim_map[2] + 10)) +

      geom_map(data = world_map, map = world_map,
      aes(x = long, y = lat, map_id = id), fill = "black") +

      geom_text(aes(x = 180, y = ylim_map[2]+5, label = "180°E"), color = "black") +
      geom_text(aes(x = 90, y = ylim_map[2]+5, label = "90°E"), angle = -90, color = "black") +
      geom_text(aes(x = 0, y = ylim_map[2]+5, label = "0°"), color = "black") +
      geom_text(aes(x = -90, y = ylim_map[2]+5, label = "90°W"), angle = 90, color = "black") +

      labs(y = "", x = "") +

      # Theme
      theme(text = element_text(size = 20),
      panel.background = element_blank(),
      axis.title = element_blank(),
      axis.text = element_blank(),
      axis.ticks = element_blank(),
      axis.line = element_blank(),
      aspect.ratio = 1)


      enter image description here










      share|improve this question
















      I map the southern part of the South hemisphere. My issue is Australia which has poorly drawn borders.



      My data :



      library("maptools")
      library("ggplot2")
      library("tidyverse")

      ylim_map <- c(-90, -30)
      xlim_map <- c(-180, 180)
      world <- maps::map("world", fill=TRUE, plot=FALSE, ylim = ylim_map)


      Convert data in correct format for ggplot :



      IDs <- sapply(strsplit(world$names, ":"), function(x) x[1])
      world <- map2SpatialPolygons(world, IDs = IDs,
      proj4string = CRS("+proj=longlat +datum=WGS84"))
      world_map <- fortify(world)
      world_map <- world_map[which(between(world_map$lat, ylim_map[1], ylim_map[2]) &
      between(world_map$lon, xlim_map[1], xlim_map[2])),]


      And my plot :



      ggplot() +

      coord_map("orthographic", orientation = c(-90, 0, 0),
      xlim = xlim_map, ylim = c(ylim_map[1], ylim_map[2] + 10)) +

      geom_map(data = world_map, map = world_map,
      aes(x = long, y = lat, map_id = id), fill = "black") +

      geom_text(aes(x = 180, y = ylim_map[2]+5, label = "180°E"), color = "black") +
      geom_text(aes(x = 90, y = ylim_map[2]+5, label = "90°E"), angle = -90, color = "black") +
      geom_text(aes(x = 0, y = ylim_map[2]+5, label = "0°"), color = "black") +
      geom_text(aes(x = -90, y = ylim_map[2]+5, label = "90°W"), angle = 90, color = "black") +

      labs(y = "", x = "") +

      # Theme
      theme(text = element_text(size = 20),
      panel.background = element_blank(),
      axis.title = element_blank(),
      axis.text = element_blank(),
      axis.ticks = element_blank(),
      axis.line = element_blank(),
      aspect.ratio = 1)


      enter image description here







      r ggplot2 maptools






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 22 at 17:25









      Z.Lin

      13.9k22343




      13.9k22343










      asked Mar 22 at 12:35









      LoulouLoulou

      31819




      31819






















          1 Answer
          1






          active

          oldest

          votes


















          1














          TLDR:



          You need to close your polygons.



          Explanation:



          Let's trim away extraneous code & zoom in onto Australia. (Though actually the problem exists for Africa & South America as well; it's just not as obvious there...)



          We can see that the top line is misbehaving. It's intersecting with the coastline further down south, rather than sticking to its correct latitude level:



          ggplot() +
          coord_map("orthographic", orientation = c(-40, 130, 0)) +
          geom_map(data = world_map, map = world_map,
          aes(x = long, y = lat, map_id=id),
          fill = "darkgrey") +
          theme_bw()


          illustration 1



          Now a geom_map layer is essentially plotting polygons, and ?geom_polygon states:




          Polygons are very similar to paths (as drawn by geom_path()) except
          that the start and end points are connected and the inside is coloured
          by fill. The group aesthetic determines which cases are connected
          together into a polygon.




          If we replace the geom_map layer with its geom_polygon / geom_path equivalents, the situation becomes much more obvious: the polygon corresponding to Australia has no top line. Instead, the path starts at the one corner and ends at the opposite corner. geom_polygon connects them with a straight line, which may intersect other lines when the coordinate system isn't linear (and coord_map isn't):



          ggplot() +
          coord_map("orthographic",
          orientation = c(-40, 130, 0)) +
          geom_polygon(data = world_map,
          aes(x = long, y = lat, group = group),
          fill = "lightgrey") +
          geom_path(data = world_map,
          aes(x = long, y = lat, group = group)) +
          theme_bw()


          illustration 2



          Solution:



          We can manually close each polygon by repeating its first point at the end. (For polygons that are already closed, this has no additional effect.)



          library(dplyr)

          world_map2 <- world_map %>%
          group_by(group) %>% # each group corresponds to a unique polygon
          arrange(order) %>% # sort points in the appropriate sequence
          slice(c(1:n(), 1)) %>% # repeat first row after last row
          mutate(order = seq(1, n())) %>% # define new order for n+1 rows
          ungroup()


          Check that the polygons are now closed, & the top line for Australia now traces its latitude level nicely:



          ggplot() +
          coord_map("orthographic",
          orientation = c(-40, 130, 0)) +
          geom_polygon(data = world_map2,
          aes(x = long, y = lat, group = group),
          fill = "lightgrey") +
          geom_path(data = world_map2,
          aes(x = long, y = lat, group = group)) +
          theme_bw()


          illustration 3



          Applying this to the original use case:



          ggplot() +

          coord_map("orthographic", orientation = c(-90, 0, 0),
          xlim = xlim_map, ylim = c(ylim_map[1], ylim_map[2] + 10)) +

          geom_map(data = world_map2, map = world_map2,
          aes(x = long, y = lat, map_id = id), fill = "black") +

          geom_text(aes(x = 180, y = ylim_map[2]+5, label = "180°E"), color = "black") +
          geom_text(aes(x = 90, y = ylim_map[2]+5, label = "90°E"), angle = -90, color = "black") +
          geom_text(aes(x = 0, y = ylim_map[2]+5, label = "0°"), color = "black") +
          geom_text(aes(x = -90, y = ylim_map[2]+5, label = "90°W"), angle = 90, color = "black") +

          labs(y = "", x = "") +

          # Theme
          theme(text = element_text(size = 20),
          panel.background = element_blank(),
          axis.title = element_blank(),
          axis.text = element_blank(),
          axis.ticks = element_blank(),
          axis.line = element_blank(),
          aspect.ratio = 1)


          result






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55299731%2fr-map-poor-representation-of-land-borders%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            TLDR:



            You need to close your polygons.



            Explanation:



            Let's trim away extraneous code & zoom in onto Australia. (Though actually the problem exists for Africa & South America as well; it's just not as obvious there...)



            We can see that the top line is misbehaving. It's intersecting with the coastline further down south, rather than sticking to its correct latitude level:



            ggplot() +
            coord_map("orthographic", orientation = c(-40, 130, 0)) +
            geom_map(data = world_map, map = world_map,
            aes(x = long, y = lat, map_id=id),
            fill = "darkgrey") +
            theme_bw()


            illustration 1



            Now a geom_map layer is essentially plotting polygons, and ?geom_polygon states:




            Polygons are very similar to paths (as drawn by geom_path()) except
            that the start and end points are connected and the inside is coloured
            by fill. The group aesthetic determines which cases are connected
            together into a polygon.




            If we replace the geom_map layer with its geom_polygon / geom_path equivalents, the situation becomes much more obvious: the polygon corresponding to Australia has no top line. Instead, the path starts at the one corner and ends at the opposite corner. geom_polygon connects them with a straight line, which may intersect other lines when the coordinate system isn't linear (and coord_map isn't):



            ggplot() +
            coord_map("orthographic",
            orientation = c(-40, 130, 0)) +
            geom_polygon(data = world_map,
            aes(x = long, y = lat, group = group),
            fill = "lightgrey") +
            geom_path(data = world_map,
            aes(x = long, y = lat, group = group)) +
            theme_bw()


            illustration 2



            Solution:



            We can manually close each polygon by repeating its first point at the end. (For polygons that are already closed, this has no additional effect.)



            library(dplyr)

            world_map2 <- world_map %>%
            group_by(group) %>% # each group corresponds to a unique polygon
            arrange(order) %>% # sort points in the appropriate sequence
            slice(c(1:n(), 1)) %>% # repeat first row after last row
            mutate(order = seq(1, n())) %>% # define new order for n+1 rows
            ungroup()


            Check that the polygons are now closed, & the top line for Australia now traces its latitude level nicely:



            ggplot() +
            coord_map("orthographic",
            orientation = c(-40, 130, 0)) +
            geom_polygon(data = world_map2,
            aes(x = long, y = lat, group = group),
            fill = "lightgrey") +
            geom_path(data = world_map2,
            aes(x = long, y = lat, group = group)) +
            theme_bw()


            illustration 3



            Applying this to the original use case:



            ggplot() +

            coord_map("orthographic", orientation = c(-90, 0, 0),
            xlim = xlim_map, ylim = c(ylim_map[1], ylim_map[2] + 10)) +

            geom_map(data = world_map2, map = world_map2,
            aes(x = long, y = lat, map_id = id), fill = "black") +

            geom_text(aes(x = 180, y = ylim_map[2]+5, label = "180°E"), color = "black") +
            geom_text(aes(x = 90, y = ylim_map[2]+5, label = "90°E"), angle = -90, color = "black") +
            geom_text(aes(x = 0, y = ylim_map[2]+5, label = "0°"), color = "black") +
            geom_text(aes(x = -90, y = ylim_map[2]+5, label = "90°W"), angle = 90, color = "black") +

            labs(y = "", x = "") +

            # Theme
            theme(text = element_text(size = 20),
            panel.background = element_blank(),
            axis.title = element_blank(),
            axis.text = element_blank(),
            axis.ticks = element_blank(),
            axis.line = element_blank(),
            aspect.ratio = 1)


            result






            share|improve this answer



























              1














              TLDR:



              You need to close your polygons.



              Explanation:



              Let's trim away extraneous code & zoom in onto Australia. (Though actually the problem exists for Africa & South America as well; it's just not as obvious there...)



              We can see that the top line is misbehaving. It's intersecting with the coastline further down south, rather than sticking to its correct latitude level:



              ggplot() +
              coord_map("orthographic", orientation = c(-40, 130, 0)) +
              geom_map(data = world_map, map = world_map,
              aes(x = long, y = lat, map_id=id),
              fill = "darkgrey") +
              theme_bw()


              illustration 1



              Now a geom_map layer is essentially plotting polygons, and ?geom_polygon states:




              Polygons are very similar to paths (as drawn by geom_path()) except
              that the start and end points are connected and the inside is coloured
              by fill. The group aesthetic determines which cases are connected
              together into a polygon.




              If we replace the geom_map layer with its geom_polygon / geom_path equivalents, the situation becomes much more obvious: the polygon corresponding to Australia has no top line. Instead, the path starts at the one corner and ends at the opposite corner. geom_polygon connects them with a straight line, which may intersect other lines when the coordinate system isn't linear (and coord_map isn't):



              ggplot() +
              coord_map("orthographic",
              orientation = c(-40, 130, 0)) +
              geom_polygon(data = world_map,
              aes(x = long, y = lat, group = group),
              fill = "lightgrey") +
              geom_path(data = world_map,
              aes(x = long, y = lat, group = group)) +
              theme_bw()


              illustration 2



              Solution:



              We can manually close each polygon by repeating its first point at the end. (For polygons that are already closed, this has no additional effect.)



              library(dplyr)

              world_map2 <- world_map %>%
              group_by(group) %>% # each group corresponds to a unique polygon
              arrange(order) %>% # sort points in the appropriate sequence
              slice(c(1:n(), 1)) %>% # repeat first row after last row
              mutate(order = seq(1, n())) %>% # define new order for n+1 rows
              ungroup()


              Check that the polygons are now closed, & the top line for Australia now traces its latitude level nicely:



              ggplot() +
              coord_map("orthographic",
              orientation = c(-40, 130, 0)) +
              geom_polygon(data = world_map2,
              aes(x = long, y = lat, group = group),
              fill = "lightgrey") +
              geom_path(data = world_map2,
              aes(x = long, y = lat, group = group)) +
              theme_bw()


              illustration 3



              Applying this to the original use case:



              ggplot() +

              coord_map("orthographic", orientation = c(-90, 0, 0),
              xlim = xlim_map, ylim = c(ylim_map[1], ylim_map[2] + 10)) +

              geom_map(data = world_map2, map = world_map2,
              aes(x = long, y = lat, map_id = id), fill = "black") +

              geom_text(aes(x = 180, y = ylim_map[2]+5, label = "180°E"), color = "black") +
              geom_text(aes(x = 90, y = ylim_map[2]+5, label = "90°E"), angle = -90, color = "black") +
              geom_text(aes(x = 0, y = ylim_map[2]+5, label = "0°"), color = "black") +
              geom_text(aes(x = -90, y = ylim_map[2]+5, label = "90°W"), angle = 90, color = "black") +

              labs(y = "", x = "") +

              # Theme
              theme(text = element_text(size = 20),
              panel.background = element_blank(),
              axis.title = element_blank(),
              axis.text = element_blank(),
              axis.ticks = element_blank(),
              axis.line = element_blank(),
              aspect.ratio = 1)


              result






              share|improve this answer

























                1












                1








                1







                TLDR:



                You need to close your polygons.



                Explanation:



                Let's trim away extraneous code & zoom in onto Australia. (Though actually the problem exists for Africa & South America as well; it's just not as obvious there...)



                We can see that the top line is misbehaving. It's intersecting with the coastline further down south, rather than sticking to its correct latitude level:



                ggplot() +
                coord_map("orthographic", orientation = c(-40, 130, 0)) +
                geom_map(data = world_map, map = world_map,
                aes(x = long, y = lat, map_id=id),
                fill = "darkgrey") +
                theme_bw()


                illustration 1



                Now a geom_map layer is essentially plotting polygons, and ?geom_polygon states:




                Polygons are very similar to paths (as drawn by geom_path()) except
                that the start and end points are connected and the inside is coloured
                by fill. The group aesthetic determines which cases are connected
                together into a polygon.




                If we replace the geom_map layer with its geom_polygon / geom_path equivalents, the situation becomes much more obvious: the polygon corresponding to Australia has no top line. Instead, the path starts at the one corner and ends at the opposite corner. geom_polygon connects them with a straight line, which may intersect other lines when the coordinate system isn't linear (and coord_map isn't):



                ggplot() +
                coord_map("orthographic",
                orientation = c(-40, 130, 0)) +
                geom_polygon(data = world_map,
                aes(x = long, y = lat, group = group),
                fill = "lightgrey") +
                geom_path(data = world_map,
                aes(x = long, y = lat, group = group)) +
                theme_bw()


                illustration 2



                Solution:



                We can manually close each polygon by repeating its first point at the end. (For polygons that are already closed, this has no additional effect.)



                library(dplyr)

                world_map2 <- world_map %>%
                group_by(group) %>% # each group corresponds to a unique polygon
                arrange(order) %>% # sort points in the appropriate sequence
                slice(c(1:n(), 1)) %>% # repeat first row after last row
                mutate(order = seq(1, n())) %>% # define new order for n+1 rows
                ungroup()


                Check that the polygons are now closed, & the top line for Australia now traces its latitude level nicely:



                ggplot() +
                coord_map("orthographic",
                orientation = c(-40, 130, 0)) +
                geom_polygon(data = world_map2,
                aes(x = long, y = lat, group = group),
                fill = "lightgrey") +
                geom_path(data = world_map2,
                aes(x = long, y = lat, group = group)) +
                theme_bw()


                illustration 3



                Applying this to the original use case:



                ggplot() +

                coord_map("orthographic", orientation = c(-90, 0, 0),
                xlim = xlim_map, ylim = c(ylim_map[1], ylim_map[2] + 10)) +

                geom_map(data = world_map2, map = world_map2,
                aes(x = long, y = lat, map_id = id), fill = "black") +

                geom_text(aes(x = 180, y = ylim_map[2]+5, label = "180°E"), color = "black") +
                geom_text(aes(x = 90, y = ylim_map[2]+5, label = "90°E"), angle = -90, color = "black") +
                geom_text(aes(x = 0, y = ylim_map[2]+5, label = "0°"), color = "black") +
                geom_text(aes(x = -90, y = ylim_map[2]+5, label = "90°W"), angle = 90, color = "black") +

                labs(y = "", x = "") +

                # Theme
                theme(text = element_text(size = 20),
                panel.background = element_blank(),
                axis.title = element_blank(),
                axis.text = element_blank(),
                axis.ticks = element_blank(),
                axis.line = element_blank(),
                aspect.ratio = 1)


                result






                share|improve this answer













                TLDR:



                You need to close your polygons.



                Explanation:



                Let's trim away extraneous code & zoom in onto Australia. (Though actually the problem exists for Africa & South America as well; it's just not as obvious there...)



                We can see that the top line is misbehaving. It's intersecting with the coastline further down south, rather than sticking to its correct latitude level:



                ggplot() +
                coord_map("orthographic", orientation = c(-40, 130, 0)) +
                geom_map(data = world_map, map = world_map,
                aes(x = long, y = lat, map_id=id),
                fill = "darkgrey") +
                theme_bw()


                illustration 1



                Now a geom_map layer is essentially plotting polygons, and ?geom_polygon states:




                Polygons are very similar to paths (as drawn by geom_path()) except
                that the start and end points are connected and the inside is coloured
                by fill. The group aesthetic determines which cases are connected
                together into a polygon.




                If we replace the geom_map layer with its geom_polygon / geom_path equivalents, the situation becomes much more obvious: the polygon corresponding to Australia has no top line. Instead, the path starts at the one corner and ends at the opposite corner. geom_polygon connects them with a straight line, which may intersect other lines when the coordinate system isn't linear (and coord_map isn't):



                ggplot() +
                coord_map("orthographic",
                orientation = c(-40, 130, 0)) +
                geom_polygon(data = world_map,
                aes(x = long, y = lat, group = group),
                fill = "lightgrey") +
                geom_path(data = world_map,
                aes(x = long, y = lat, group = group)) +
                theme_bw()


                illustration 2



                Solution:



                We can manually close each polygon by repeating its first point at the end. (For polygons that are already closed, this has no additional effect.)



                library(dplyr)

                world_map2 <- world_map %>%
                group_by(group) %>% # each group corresponds to a unique polygon
                arrange(order) %>% # sort points in the appropriate sequence
                slice(c(1:n(), 1)) %>% # repeat first row after last row
                mutate(order = seq(1, n())) %>% # define new order for n+1 rows
                ungroup()


                Check that the polygons are now closed, & the top line for Australia now traces its latitude level nicely:



                ggplot() +
                coord_map("orthographic",
                orientation = c(-40, 130, 0)) +
                geom_polygon(data = world_map2,
                aes(x = long, y = lat, group = group),
                fill = "lightgrey") +
                geom_path(data = world_map2,
                aes(x = long, y = lat, group = group)) +
                theme_bw()


                illustration 3



                Applying this to the original use case:



                ggplot() +

                coord_map("orthographic", orientation = c(-90, 0, 0),
                xlim = xlim_map, ylim = c(ylim_map[1], ylim_map[2] + 10)) +

                geom_map(data = world_map2, map = world_map2,
                aes(x = long, y = lat, map_id = id), fill = "black") +

                geom_text(aes(x = 180, y = ylim_map[2]+5, label = "180°E"), color = "black") +
                geom_text(aes(x = 90, y = ylim_map[2]+5, label = "90°E"), angle = -90, color = "black") +
                geom_text(aes(x = 0, y = ylim_map[2]+5, label = "0°"), color = "black") +
                geom_text(aes(x = -90, y = ylim_map[2]+5, label = "90°W"), angle = 90, color = "black") +

                labs(y = "", x = "") +

                # Theme
                theme(text = element_text(size = 20),
                panel.background = element_blank(),
                axis.title = element_blank(),
                axis.text = element_blank(),
                axis.ticks = element_blank(),
                axis.line = element_blank(),
                aspect.ratio = 1)


                result







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 22 at 17:23









                Z.LinZ.Lin

                13.9k22343




                13.9k22343





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55299731%2fr-map-poor-representation-of-land-borders%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현