Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Update to geoplot available from SSC

    A new version of geoplot is available from SSC. Type ssc install geoplot, replace to install the new version. For details on changes see github.com/benjann/geoplot/.

    There is a new geograme pcpath command to connect points along the shortest path on the sphere (great-circle arc, "as the crow flies"). Here's an illustration using Wesley Stubenbord's data on Billionaires (github.com/wstubenbord/Billionaire-Migration-Map):

    Code:
    // load base map (outlines of countries)
    local url https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/
    geoframe create countries `url'ne_110m_admin_0_countries.geojson
    // fix precision issue in base map
    frame countries_shp: replace _X = 180 if _X>180 & _X<.
    // generate grid lines
    frame countries: geoframe grid grid
    
    // load billionaire data
    local url https://raw.githubusercontent.com/wstubenbord/Billionaire-Migration-Map/main/data/
    import delimited `url'migration_map.csv, encoding(UTF-8)
    // declare as paired-coordinates data
    geoframe create, coordinates(birthlong birthlat reslong reslat)
    // create arcs connecting birthplace and place of residence
    geoframe pcpath paths
    // agregate birth data
    frame copy default birth
    frame birth {
        contract birth*
        geoframe create, type(attribute) coord(birthlong birthlat)
    }
    // agregate residence data
    frame copy default res
    frame res {
        contract res*
        geoframe create, type(attribute) coord(reslong reslat)
    }
    
    // draw graph
    geoplot ///
        (area countries, fcol(white)) (line grid) /// world
        (line paths, col(stc3%50)) /// connecting arcs
        (symbol birth [iw=_freq], size(*2) color(stc2%70)) /// birthplace
        (symbol res   [iw=_freq], size(*2) color(stc1%70)) /// residence
        , project(robinson) background(color(Azure)) tight ///
          slegend(10 50 100, overlay tsize(1.75) pos(nw) ///
              title("Billionaires", pos(11))) ///
          glegend(l(4 "Birthplace" 5 "Residence") symscale(0.6) pos(sw) ///
              title("Location", pos(11)))
    Click image for larger version

Name:	Graph1.png
Views:	1
Size:	901.3 KB
ID:	1787278


    Furthermore, new command geoframe makepc can be used to extract segments of a line or polygon into paired-coordinates data. This is useful if you want to draw arrows. An illustration is as follows:

    Code:
    // select two rich guys born in Switzerland
    frame copy default richguys
    frame richguys: keep if inlist(person_id, 2561, 4725)
    // create connecting arcs, shortened by one point on each side
    frame richguys: geoframe pcpath arc, shorten(1)
    // get last segment of each path and store as paired-coordinate data
    frame arc: geoframe makepc arrow, last
    
    // draw graph
    geoplot ///
        (area countries, fcol(white)) (line grid) /// world
        (pcpoint richguys, color(stc2)) /// birthplace and residence
        (line arc, col(stc3) lw(.5)) /// connecting arcs
        (pcarrow arrow, mcol(stc3) mlw(.5) lcolor(%0)) /// arrowheads
        , project(robinson) background(color(Azure)) tight
    Click image for larger version

Name:	Graph2.png
Views:	1
Size:	351.8 KB
ID:	1787279

    Quiz: who are the two guys?

    ben

  • #2
    Beautiful! This is Stata's glory.

    Comment


    • #3
      Thanks, Ben!
      Quiz: who are the two guys?
      One guy is Harald Link, but the other?
      Best wishes

      Stata 18.0 MP | ORCID | Google Scholar

      Comment


      • #4
        1 point for Felix.

        Comment


        • #5
          Hansjörg Wyss

          Comment


          • #6
            Bingo.

            Comment

            Working...
            X