Announcement

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

  • Odd diagonal line emerge when I draw a two-way line graph

    Hi, I encountered a strange situation when I want to draw a two-way line graph using Stata. Besides the two lines which I desired, there is also a third diagonal line across the plot region, which I though was due to the second line. After carefully check my code, I still could not find the source of my problem. Could someone have a look and provide some guide, thanks in advance. I put the original data and code in the attachment.

    Code:
     # delimit ;
    twoway 
           (line ownersh_ownership2013        xlabel if xlabel>=20&xlabel<=58 ,lwidth(medthick))
           (line ownersh_ownership2011        xlabel if xlabel>=20&xlabel<=58 ,lwidth(medthick))  
        ,     
       xlabel(20 "20" 22 "22" 24 "24" 26 "26" 28 "28" 30 "30" 32 "32" 34 "34" 36 "36" 
              38 "38" 40 "40" 42 "42" 44 "44" 46 "46" 48 "48" 50 "50" 52 "52" 54 "54"
              56 "56" 58 "58"  ,
               angle(0))
       ylabel(.2 "20" .3 "30" .4 "40" .5 "50" .6 "60" .7 "70" .8 "80" .9 "90",grid)           
       title("")                           
       ytitle("家庭住房拥有率(%)",size(small)) // Homeownership
       xtitle("年龄",size(small))              // cohorts 
       legend (order(1 "2013年调查" 2 "2011年调查" ) 
               size(mall) region(lcolor(white)) col(1) ring(0) pos(5) )           
      scheme(s1color)
      saving(ownersh_by_wave,replace);  
    # delimit cr
    Click image for larger version

Name:	QQ截图20161209222619.jpg
Views:	1
Size:	30.3 KB
ID:	1367212

    Attached Files

  • #2
    Try adding

    Code:
    sort
    as an extra option.

    By the way

    Code:
    xlabel(20 "20" 22 "22" 24 "24" 26 "26" 28 "28" 30 "30" 32 "32" 34 "34" 36 "36"  38 "38" 40 "40" 42 "42" 44 "44" 46 "46" 48 "48" 50 "50" 52 "52" 54 "54"  56 "56" 58 "58" , angle(0))
    reduces to

    Code:
    xla(20(2)58)

    Comment


    • #3
      Got it, thanks, Nick

      Comment

      Working...
      X