Announcement

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

  • mlabel overlay vs mlabel disperse

    Dear Stata Users,

    I‘ve been tried to graph twoway plots (connected, scatter, etc.) and made them more readable. But in some cases, the markers' text label will all overlay with each other, so I wonder if there are some tricks in Stata to solve this kind of question (-jitter()- option seems ineffective). As I know, this goal can be reached in some software. I paste Stata code, dataset and plots (mlabel overly vs mlabel disperse) as follows:

    Code:
    twoway connected grow* id if scountry<50, sort mlabel(scountry) ///
     legend(ring(0) posi(1) col(1) symxsize(*0.6) ///
     order(1 "tertiary enroll growth" 2 "primary enroll growth" 3 "secondary enroll growth")) xtitle("")
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int scountry float(grow1 grow2 grow3 id)
      9  19.782234   .6912025    13.44257  1
     30   .7962048  -1.422295   12.878456 30
     36   7.405934   1.822175    9.165301 12
     16   9.309525  .17639677    7.423643 11
     18  11.291667   1.960192    6.311147  6
      2   5.669756  .27983347    4.790659 16
      8  13.724893   .3030292   4.7054443  3
     21  12.151047  1.5711125    4.147221  5
     10  -4.600931 -.15420157    3.417848 39
     15   3.725703  -.1749033    3.128709 20
     32  10.588955 -1.4353393   2.4328065  7
      6   1.084179 -.04416964   2.3612878 29
     11  2.3613307   .3262071   2.2868495 23
     17    9.44123   .8550048   2.2842023  9
     43   1.667928  1.2576123    2.260211 27
     46  10.022378  .01638453   2.1331606  8
     22  4.1329155   -.389468    1.585396 19
     26   2.983327   .3373509   1.4069656 21
     19   7.301531   2.179176    1.335049 14
     41          .  1.6605814   1.1985422 42
     44  1.7694622   .5502587    1.123282 25
     24   .1646451   .7771235   1.0238218 33
     37 -1.1726909  .02315044    .5794858 36
     33  4.7665997 -.08377693    .5433005 18
     12   .4959584  .25510532   .28751516 31
      4  1.1814398 -.13026316   .13925686 28
     35    1.73324 -.07265969  .062681675 26
     29 -.06444957  18.554337 .0040602237 34
     27   -1.93765    .236446  -.06069905 38
     25   2.173939   .7590757   -.2901005 24
     38 -1.4842654 -.14696115   -.4161985 37
     39  -5.211161 -.12401387   -.4452422 40
     13   6.574399 -.18428287   -.4882415 15
     34   .1953333 -2.2679708  -1.1059465 32
     31     9.3632   .6392944  -1.1515096 10
      7   5.393747 .025500586           . 17
      1  12.605727   .4742768           .  4
     42 -.53985846   2.983732           . 35
     40          .   2.495012           . 45
     28          .          .           . 44
    211          .          .           . 43
     45    2.92467   .6364408           . 22
     23  16.322706  -2.447301           .  2
     20   7.372392   .6717668           . 13
     14          .          .           . 41
    end
    label values scountry scountry
    label def scountry 1 "中国", modify
    label def scountry 2 "蒙古", modify
    label def scountry 4 "韩国", modify
    label def scountry 6 "菲律宾", modify
    label def scountry 7 "越南", modify
    label def scountry 8 "老挝", modify
    label def scountry 9 "柬埔寨", modify
    label def scountry 10 "缅甸", modify
    label def scountry 11 "泰国", modify
    label def scountry 12 "马来西亚", modify
    label def scountry 13 "文莱", modify
    label def scountry 14 "新加坡", modify
    label def scountry 15 "印度尼西亚", modify
    label def scountry 16 "东帝汶", modify
    label def scountry 17 "尼泊尔", modify
    label def scountry 18 "不丹", modify
    label def scountry 19 "孟加拉国", modify
    label def scountry 20 "印度", modify
    label def scountry 21 "巴基斯坦", modify
    label def scountry 22 "斯里兰卡", modify
    label def scountry 23 "马尔代夫", modify
    label def scountry 24 "哈萨克斯坦", modify
    label def scountry 25 "吉尔吉斯斯坦", modify
    label def scountry 26 "塔吉克斯坦", modify
    label def scountry 27 "乌兹别克斯坦", modify
    label def scountry 28 "土库曼斯坦", modify
    label def scountry 29 "阿富汗", modify
    label def scountry 30 "伊拉克", modify
    label def scountry 31 "伊朗", modify
    label def scountry 32 "叙利亚", modify
    label def scountry 33 "约旦", modify
    label def scountry 34 "黎巴嫩", modify
    label def scountry 35 "以色列", modify
    label def scountry 36 "沙特阿拉伯", modify
    label def scountry 37 "巴林", modify
    label def scountry 38 "卡塔尔", modify
    label def scountry 39 "科威特", modify
    label def scountry 40 "阿拉伯联合酋长国(阿联酋)", modify
    label def scountry 41 "阿曼", modify
    label def scountry 42 "也门", modify
    label def scountry 43 "格鲁吉亚", modify
    label def scountry 44 "亚美尼亚", modify
    label def scountry 45 "阿塞拜疆", modify
    label def scountry 46 "土耳其", modify
    label def scountry 211 "巴勒斯坦", modify
    Click image for larger version

Name:	mlabel overlay.png
Views:	1
Size:	112.4 KB
ID:	1428665 Click image for larger version

Name:	mlabel disperse.png
Views:	1
Size:	354.8 KB
ID:	1428666

  • #2
    Supplement: the variable id is labeled as "sorted by growth1", where the variable growth1 represents tretiary enroll rate growth per country.
    And I know there is an option -labvpostion- in twoway plots, but assignment of every label position is somewhat inconvenient. Thank you.
    Last edited by Chen Samulsion; 03 Feb 2018, 19:44.

    Comment


    • #3
      Ulrich Kohler wrote an egen function mlabvpos() to automate putting labels towards the periphery of the graph.

      It's in egenmore (SSC).

      But in general if you have lots of labels and lots of data the labels are likely to overlap whatever you do. In much other software, as you will know, labels appear only interactively on a mouse-over.

      Comment


      • #4
        Hello, Nick, thank you as always and much appreciate for reminding me the -egenmore- (I haven't explored it much deep). And just as what you have said in other place, overlays among many markers' label is inevitable. I think I can close this thread without regrets.

        https://www.statalist.org/forums/for...ing-the-labels

        Originally posted by Nick Cox View Post
        ……you have dozens of data points, some text will predictably occlude something else whatever you do.
        Last edited by Chen Samulsion; 04 Feb 2018, 08:54.

        Comment

        Working...
        X