Announcement

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

  • graph with a small line?

    Dear All, I have this graph
    Click image for larger version

Name:	g1.png
Views:	1
Size:	43.7 KB
ID:	1488547

    by the following data and code.
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(growth lprivo) str3 code
      .6176451  2.752746 "ARG"
     1.9751474  4.004016 "AUS"
      2.889185  4.178968 "AUT"
      .7082631 2.6060796 "BGD"
      2.652859  3.704847 "BRB"
     2.6513345 3.2444575 "BEL"
      .3550578 2.5758026 "BOL"
     2.9300966  3.065546 "BRA"
     2.3859885 4.1086454 "CAN"
     1.4469954   3.32541 "CHL"
     2.2270143  3.094773 "COL"
     1.6136966 3.0807066 "CRI"
      5.384184  4.127378 "CYP"
     2.1793702  3.748256 "DNK"
      2.498769 2.9503646 "DOM"
      2.388093  2.889542 "ECU"
     -.6075561 3.1289306 "SLV"
     1.8458964  3.163393 "FJI"
      2.798494  3.947039 "FIN"
      2.431281  4.323712 "FRA"
      2.453688  4.336713 "DEU"
     -.9631622 1.6240644 "GHA"
       3.22405   3.60341 "GRC"
      .9292306  2.589061 "GTM"
    -.28062087  3.021234 "GUY"
     -.6579341  2.042972 "HTI"
      .5977848 3.1720316 "HND"
      3.012389 3.5494244 "ISL"
      1.915168 2.9719946 "IND"
      3.254494 3.8947036 "IRL"
      2.810969  3.622525 "ISR"
     2.9329815 4.0790596 "ITA"
      .4177902  3.200545 "JAM"
      4.304759  4.854981 "JPN"
      1.962509 3.1259286 "KEN"
      7.156855 4.1817265 "KOR"
     -.4721583  2.318493 "LBR"
      4.114544 3.8480165 "MYS"
      6.652838 3.7835095 "MLT"
      3.024178 3.1929696 "MUS"
     1.9739418  3.130883 "MEX"
      .7671511  2.044247 "NPL"
     2.2005773 4.4623857 "NLD"
     1.1241318  3.626801 "NZL"
     -2.751478  2.568801 "NER"
      3.182494  4.402111 "NOR"
      2.698163 3.0333946 "PAK"
     2.0271885  3.694385 "PAN"
     1.1203711  3.037085 "PNG"
     2.3819315 2.6755195 "PRY"
     .06020596  2.589619 "PER"
     1.1587406 3.2949524 "PHL"
       3.64731 4.0075636 "PRT"
     -.4378241 3.3143885 "SEN"
     -.3398342 1.6226246 "SLE"
      .3920211  4.275775 "ZAF"
      2.880327  4.175143 "ESP"
     2.7045984 2.7856154 "LKA"
     1.8881342 4.4898977 "SWE"
     1.4218653  4.950846 "CHE"
      2.511772 2.1776114 "SYR"
      6.624734  4.057945 "TWN"
      4.876695  3.856032 "THA"
      .4627753 3.0857854 "TGO"
     1.1207864 3.4465425 "TTO"
     1.9622195  3.835404 "GBR"
      1.712265   4.72797 "USA"
     1.0253086 3.0545275 "URY"
     -.8835508  3.500184 "VEN"
    -2.8119445 1.4072825 "ZAR"
      .8381555  3.137074 "ZWE"
    end
    
    twoway (scatter growth lprivo, mlabel(code) ms(oh)) (lfit growth lprivo), ytitle(growth) legend(off)
    I'd like to have a short line (for example, Netherlands, France, Portugal) like the following graph (Note that the data sets are different).
    Click image for larger version

Name:	g2.jpeg
Views:	1
Size:	41.4 KB
ID:	1488548

    Any suggestions? Thanks.
    Ho-Chuan (River) Huang
    Stata 15.1, MP(4)

  • #2
    Use twoway scatteri, recast(line) for coordinate pairs defining each line end. If you post the data other kinds of plots can be suggested.

    Comment


    • #3
      Dear Nick, Thanks for the suggestion. No data for the second graph but the data for the first graph is provided above.
      Ho-Chuan (River) Huang
      Stata 15.1, MP(4)

      Comment


      • #4
        Indeed you did. Roughly speaking, you have twice as many countries as the example graph and even with the use of TLIs (three letter identfiers) it's going to be hard to avoid a real mess. I have two main suggestions:

        1. You don't really need the identifiers and the data points. Let each identifier serve as data point.

        2. Ambition is fine, but achievement can be enough. Just show the exceptional points.

        Beyond that, I have suggestions on graph appearance and etiquette.

        A. s2color defines Stata house style, but it is widely disliked -- as twitterings on social media make evident. To appeal to more readers, use almost anything else.

        B. For growth (define more precisely) a reference line of zero is a good possibility. (Note that the exemplar grapher forgot to explain what is on their y axis!)

        C. Use a variable label for lprivo.

        D. Units of measurement?

        E. Rotate your y axis labels to horizontal.

        Code:
        set scheme s1color
        scatter growth lprivo, mlabel(code) mlabpos(0) mlabc(black) ms(none) ///
        || lfit growth lprivo, ytitle(growth) legend(off) yla(, ang(h)) yli(0, lc(gs12) lw(thin)) name(river1, replace)
        
        regress growth lprivo
        predict residual, res
        twoway lfit growth lprivo, ytitle(growth) legend(off) || scatter growth lprivo if abs(residual) > 1.5 , mlabel(code) mlabpos(0) mlabc(black) ms(none) ///
        || scatter growth lprivo if abs(residual) <= 1.5, ms(Oh)  yla(, ang(h)) yli(0, lc(gs12) lw(thin)) name(river2, replace)
        Click image for larger version

Name:	river__1.png
Views:	1
Size:	26.9 KB
ID:	1488579

        Last edited by Nick Cox; 17 Mar 2019, 02:18.

        Comment


        • #5
          Here's the second graph.


          Click image for larger version

Name:	river__2.png
Views:	1
Size:	30.0 KB
ID:	1488583

          Comment


          • #6
            Dear Nick, Thanks, and I like your suggestions. Just for curiosity (I was asked this question), how exactly to use twoway scatteri, recast(line) to add a short line?
            Ho-Chuan (River) Huang
            Stata 15.1, MP(4)

            Comment


            • #7
              What's puzzling here?

              Code:
              help twoway scatteri
              explains how to use the command and recast(line) was explained as the option to add. As an example,

              Code:
              twoway scatteri  1  1 2 2 , recast(line)
              Now if you want lots of these, you have to specify lots of little lines, and that's tedious. But

              1. Arguably, the graph design is trying too much in that case.

              2. You could use twoway pcspike if you have the start and end coordinates in variables, but then you need to work out what those variables should be.

              3. If the graph is one-off, moving labels around in the Graph Editor might be as easy and effective.

              (From previous posts, it seems that you are asking questions for others, but the same expectations apply to proxy members too, i.e. please try to read the help and don't act clueless.)

              Comment


              • #8
                Dear Nick, I will go through the help file. Thanks again.
                Ho-Chuan (River) Huang
                Stata 15.1, MP(4)

                Comment

                Working...
                X