Announcement

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

  • Creating partial maps

    I have a dataset which defines the boundaries and geographic regions of the world's countries, as shown below:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int _ID double(_X _Y) str39 CNTRY_NAME str25 GEO
    1                 .                . "Aruba" "Caribbean"
    1 -69.8822326660156 12.4111099243165 "Aruba" "Caribbean"
    1 -69.9469451904296 12.4366655349731 "Aruba" "Caribbean"
    1 -70.0590362548828 12.5402078628541 "Aruba" "Caribbean"
    1 -70.0596618652343 12.6277761459352 "Aruba" "Caribbean"
    1 -70.0331954956055 12.6183319091797 "Aruba" "Caribbean"
    1 -69.9322357177734 12.5280551910401 "Aruba" "Caribbean"
    1 -69.8969573974609 12.4808330535889 "Aruba" "Caribbean"
    1 -69.8914031982421 12.4722213745117 "Aruba" "Caribbean"
    1 -69.8855590820313 12.4577770233155 "Aruba" "Caribbean"
    end
    I can construct a fairly simple map using this data with a command like:

    Code:
    tw area _Y _X , nodropbase cmiss(n) fcolor(white) lcolor(black) lwidth(vthin) scheme(s1color) legend(off) xla(none) yla(none) xtitle("") ytitle("") plotregion(fcolor(gs13) margin(zero))
    However, I would like to construct a "zoomed in" map, focused on a specific region. I do not want to just use an if condition to limit the map to that region, because doing so produces a context-less map in which the specified region appears to be floating in space, with no bordering countries. Instead, I want to create a map which focuses on the region I am interested in, but which also shows a small section of the edge of neighboring countries. For instance, if my region of interest was Africa and the Middle East, I would want a map containing only the section bordered by the red square in the below image, which includes some of Europe and Asia:
    Click image for larger version

Name:	basemap.png
Views:	1
Size:	188.8 KB
ID:	1706145




    I attempted the following:

    Code:
    sum _Y if inlist(GEO,"Region Of Interest")
    local min_lat = r(min)
    local max_lat = r(max)
    sum _X if inlist(GEO,"Region Of Interest")
    local min_lon = r(min)
    local max_lon = r(max)
    
    tw area _Y _X if _Y>=`min_lat' & _Y<=`max_lat' & _X>=`min_lon' & _X<=`max_lon', nodropbase cmiss(n) fcolor(white) lcolor(black) lwidth(vthin) scheme(s1color) legend(off) xla(none) yla(none) xtitle("") ytitle("") plotregion(fcolor(gs13) margin(zero))
    This does not produce the desired result, because the borders of the neighboring countries are "cut-off", leaving them hanging, and they therefore stretch across the map in an undesirable way.

    How might I achieve the desired result?
    Last edited by Ali Atia; 18 Mar 2023, 13:33.

  • #2
    In these maps, you mess up the order of observations or omit some points and the map won't look as it should do. You want to maintain the observations as they are and replace any points above or below a threshold with that threshold.

    Code:
    use http://pped.org/usa, clear
    tw area _Y _X , nodropbase cmiss(n) fcolor(white) lcolor(black) lwidth(vthin) scheme(s1color) legend(off) xla(none) yla(none) xtitle("") ytitle("") plotregion(fcolor(gs13) margin(zero))
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	126.1 KB
ID:	1706158



    Code:
    *NOW ZOOM IN
    use http://pped.org/usa, clear
    gen _Y2= cond( _Y>45 &!missing(_Y), 45, _Y)
    replace _Y2= cond( _Y2<30, 30, _Y2)
    gen _X2= cond( _X<-120, -120, _X)
    replace _X2= cond( _X2>-80 & !missing(_X2), -80, _X2)
    tw area _Y2 _X2 , nodropbase cmiss(n) fcolor(white) lcolor(black) lwidth(vthin) scheme(s1color) legend(off) xla(none) yla(none) xtitle("") ytitle("") plotregion(fcolor(gs13) margin(zero))
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	110.6 KB
ID:	1706159

    Comment

    Working...
    X