Announcement

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

  • Show the data in the graph


    Hi, friends, might I be able to show the values of the data in the graph? My initial command is,

    sysuse uslifeexp

    twoway line le year
    Thank you a lot!
    Last edited by Bright Tree; 09 Apr 2020, 21:15.

  • #2
    The usual way to do this is to superimpose a scatter plot with marker labels while hiding the markers. However, with too many data points, it may not be feasible to show all the values. Below I illustrate how to show every 5th or every 10th value.

    Code:
    sysuse uslifeexp
    *ALL VALUES
    twoway (line le year, scheme(s1color) leg(order(1))) ///
    (scatter le year, mlab(le) mlabpos(0) mcolor(none))
    *EVERY 5TH VALUE
    gen le2=cond(mod(_n, 5)==0, string(le), "")
    twoway (line le year, scheme(s1color) leg(order(1))) ///
    (scatter le year, mlab(le2) mlabpos(0) mcolor(none))
    *EVERY 10TH VALUE
    gen le3=cond(mod(_n, 10)==0, string(le), "")
    twoway (line le year, scheme(s1color) leg(order(1))) ///
    (scatter le year, mlab(le3) mlabpos(0) mcolor(none))
    Res.:
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	73.3 KB
ID:	1545908

    Last edited by Andrew Musau; 09 Apr 2020, 22:57.

    Comment


    • #3
      Andrew Musau's helpful post underlines the difficulties here. Why don't people do this more often? Perhaps because showing data numerically while graphing them seems redundant. Perhaps because it is hard to avoid a mess.

      Still, riffing on this theme, Here are some related possibilities.


      Code:
      sysuse uslifeexp, clear 
      
      gen show = round(le, 1)
      
      gen where1 = 78 
      
      gen where2 = 38
      
      twoway line le year, scheme(s1color) leg(order(1)) ///
      || scatter where1 year if mod(year, 5) == 0, ms(none) mlab(show) mlabpos(0) mcolor(none) ///
      || scatter where2 year if year == 1918, ms(none) mlab(show) mlabpos(0) legend(off)       ///
      yla(40(5)75, ang(h)) ytitle("Life expectancy (years)") xtitle("")
      Click image for larger version

Name:	lifeexp.png
Views:	1
Size:	32.0 KB
ID:	1546028

      Comment


      • #4
        Thank you very much to Profs. Andrew and Nick.

        Comment

        Working...
        X