Announcement

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

  • meeting x and y axis at zero


    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(lograte time pred_withseason pred_withoutseason adm_year) byte adm_mon
     5.984276   1  5.667077 5.748545 2006  4
     5.647804   2  5.311514 5.747315 2006  5
     5.291129   3  5.444794 5.746085 2006  6
     5.910168   4  5.772729 5.744855 2006  7
     5.984276   5   5.67867 5.743625 2006  8
     5.743114   6  5.614248 5.742395 2006  9
     5.910168   7  5.851193 5.741165 2006 10
      5.42466   8   6.01965 5.739935 2006 11
     6.564095   9  5.945833 5.738705 2006 12
     6.505072  10  5.967428 5.737474 2007  1
     5.966075  11  5.899466 5.736245 2007  2
     5.811924  12  5.982559 5.735014 2007  3
      4.42563  13  5.646421 5.733784 2007  4
     5.272928  14  5.290859 5.732554 2007  5
     5.891967  15  5.424139 5.731324 2007  6
     5.406459  16  5.752075 5.730094 2007  7
     5.724913  17  5.658015 5.728864 2007  8
     5.891967  18  5.593593 5.727634 2007  9
     5.724913  19  5.830538 5.726404 2007 10
      6.21739  20  5.998995 5.725174 2007 11
     6.099607  21  5.925178 5.723944 2007 12
     6.214238  22  5.946773 5.722714 2008  1
     5.808773  23  5.878811 5.721484 2008  2
     5.626451  24  5.961904 5.720253 2008  3
     5.403307  25  5.625767 5.719024 2008  4
     5.521091  26  5.270204 5.717793 2008  5
     5.403307  27  5.403484 5.716564 2008  6
     5.721761  28   5.73142 5.715333 2008  7
     6.096455  29  5.637361 5.714103 2008  8
     5.888815  30  5.572938 5.712873 2008  9
     5.888815  31  5.809884 5.711643 2008 10
     4.933304  32  5.978341 5.710413 2008 11
     5.115625  33  5.904523 5.709183 2008 12
     5.853778  34  5.926118 5.707953 2009  1
     6.122042  35  5.858156 5.706723 2009  2
     6.061418  36  5.941249 5.705493 2009  3
      5.36827  37  5.605112 5.704263 2009  4
     4.675123  38  5.249549 5.703033 2009  5
     5.486053  39  5.382829 5.701803 2009  6
     5.773736  40  5.710765 5.700572 2009  7
     6.379871  41  5.616705 5.699343 2009  8
     5.591414  42  5.552283 5.698112 2009  9
     5.927886  43  5.789228 5.696882 2009 10
     6.233268  44  5.957685 5.695652 2009 11
     6.233268  45  5.883868 5.694422 2009 12
     6.368409  46  5.905463 5.693192 2010  1
     5.916423  47  5.837501 5.691962 2010  2
     5.842315  48  5.920594 5.690732 2010  3
     5.675261  49  5.584457 5.689502 2010  4
     5.474591  50  5.228894 5.688272 2010  5
     5.474591  51  5.362175 5.687042 2010  6
     5.223276  52   5.69011 5.685812 2010  7
     6.049955  53  5.596051 5.684582 2010  8
     5.762273  54  5.531628 5.683352 2010  9
     5.356808  55  5.768574 5.682122 2010 10
     5.356808  56  5.937031 5.680892 2010 11
     5.675261  57  5.863213 5.679662 2010 12
      5.47245  58         .        . 2011  1
     5.914283  59         .        . 2011  2
      5.47245  60         .        . 2011  3
      4.66152  61  4.945485 5.009988 2011  4
     4.373838  62 4.5899224 5.008758 2011  5
      4.66152  63  4.723202 5.007528 2011  6
      4.66152  64  5.051137 5.006298 2011  7
     5.354667  65  4.957078 5.005068 2011  8
     4.884664  66  4.892656 5.003838 2011  9
     5.066985  67  5.129601 5.002607 2011 10
     5.354667  68  5.298059 5.001378 2011 11
      4.66152  69  5.224241 5.000147 2011 12
     5.211245  70  5.245836 4.998917 2012  1
     5.462559  71  5.177874 4.997687 2012  2
     5.462559  72  5.260967 4.996457 2012  3
     4.874772  73   4.92483 4.995227 2012  4
    3.9584816  74 4.5692673 4.993997 2012  5
    4.3639464  75  4.702547 4.992767 2012  6
     5.344776  76  5.030483 4.991537 2012  7
    4.3639464  77  4.936423 4.990307 2012  8
    3.9584816  78  4.872001 4.989077 2012  9
     4.874772  79  5.108947 4.987847 2012 10
     5.973384  80  5.277404 4.986617 2012 11
    4.6516285  81  5.203586 4.985387 2012 12
     5.354535  82  5.225181 4.984157 2013  1
     4.661388  83  5.157219 4.982926 2013  2
     4.884531  84  5.240312 4.981697 2013  3
     5.066853  85  4.904175 4.980466 2013  4
     4.884531  86 4.5486126 4.979236 2013  5
     5.066853  87 4.6818924 4.978006 2013  6
     5.066853  88  5.009828 4.976776 2013  7
     4.373706  89  4.915769 4.975546 2013  8
     5.221004  90  4.851346 4.974316 2013  9
     5.066853  91  5.088292 4.973086 2013 10
     5.672989  92  5.256749 4.971856 2013 11
     3.968241  93  5.182931 4.970626 2013 12
     5.230325  94  5.204526 4.969396 2014  1
        5.587  95  5.136564 4.968166 2014  2
      5.68231  96  5.219657 4.966936 2014  3
     4.893853  97   4.88352 4.965705 2014  4
     4.893853  98 4.5279574 4.964476 2014  5
        5.587  99 4.6612372 4.963245 2014  6
     5.363856 100  4.989173 4.962015 2014  7
    end
    ------------------ copy up to and including the previous line ------------------

    Listed 100 out of 165 observations
    Use the count() option to list more

    code
    set scheme s2color
    twoway (scatter lograte time if time, msize(vsmall) xline(57, lpattern(shortdash) lwidth(thin) lcolor(black)) ///
    xline(61, lpattern(shortdash) lwidth(thin) lcolor(black))) ///
    (line pred_withseason time if time<58,lcolor(green)) (line pred_withseason time if time>60,lcolor(green)) ///
    (line pred_withoutseason time if time<58, lwidth(thin) lcolor(cranberry)) (line pred_withoutseason time if time>60, lwidth(thin) lcolor(cranberry)), ///
    graphregion(color(white)) ylab(3.91 "50" 4.61 "100" 5.30 "200" 5.99 "400" 6.40 "600", angle(hor) labsize(vsmall) nogrid) xtitle("Years", size(small)) ytitle("Incidence rates per 100,000 person-years(log{subscript:10}scale)", size(small)) ///
    bgcolor(white) legend(position(2) cols(1) size(vsmall) order(1 2 4) symxsize(2)lab(1 "Monthly incidence") lab(2 "Temporal trend and season") lab(4 "Temporal trend") width(26) region(lcolor(white))) xlab(5 "2006" 15.5 "2007" 27.5 "2008" 39.5 "2009" 51.5 "2010" 63.5 "2011" ///
    75.5 "2012" 87.5 "2013" 99.5 "2014" 111.5 "2015" 123.5 "2016" 135.5 "2017" 147.5 "2018" 159.5 "2019", noticks labsize(vsmall)) yscale(titlegap(*6)) xscale(titlegap(*6)) ///
    title("{bf:radiologically-defined pneumonia 2-59 months}", size(small)) xsize(9) ysize(5) plotregion(margin(zero)) xtick(0 9 21 33 45 57 69 81 93 105 117 129 141 153 165 )
    e

    Dear all,
    Above is my code and data, why is it that if I use plotregion(margin(zero)) the two data points of 2016 (june and december ) which are 3.31 for lograte fall in x-axis line? I just want x and y axis to meet at zero (0,0).Does this mean x and y-axis meet at (3.31,0)? i.e is x-axis drawn at 3.31 ?.Maybe am not getting something.Kindly assist




  • #2
    Sorry I realised I did not include the whole dataset. below is the whole data

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(lograte time pred_withseason pred_withoutseason adm_year)
     5.984276   1  5.667077 5.748545 2006
     5.647804   2  5.311514 5.747315 2006
     5.291129   3  5.444794 5.746085 2006
     5.910168   4  5.772729 5.744855 2006
     5.984276   5   5.67867 5.743625 2006
     5.743114   6  5.614248 5.742395 2006
     5.910168   7  5.851193 5.741165 2006
      5.42466   8   6.01965 5.739935 2006
     6.564095   9  5.945833 5.738705 2006
     6.505072  10  5.967428 5.737474 2007
     5.966075  11  5.899466 5.736245 2007
     5.811924  12  5.982559 5.735014 2007
      4.42563  13  5.646421 5.733784 2007
     5.272928  14  5.290859 5.732554 2007
     5.891967  15  5.424139 5.731324 2007
     5.406459  16  5.752075 5.730094 2007
     5.724913  17  5.658015 5.728864 2007
     5.891967  18  5.593593 5.727634 2007
     5.724913  19  5.830538 5.726404 2007
      6.21739  20  5.998995 5.725174 2007
     6.099607  21  5.925178 5.723944 2007
     6.214238  22  5.946773 5.722714 2008
     5.808773  23  5.878811 5.721484 2008
     5.626451  24  5.961904 5.720253 2008
     5.403307  25  5.625767 5.719024 2008
     5.521091  26  5.270204 5.717793 2008
     5.403307  27  5.403484 5.716564 2008
     5.721761  28   5.73142 5.715333 2008
     6.096455  29  5.637361 5.714103 2008
     5.888815  30  5.572938 5.712873 2008
     5.888815  31  5.809884 5.711643 2008
     4.933304  32  5.978341 5.710413 2008
     5.115625  33  5.904523 5.709183 2008
     5.853778  34  5.926118 5.707953 2009
     6.122042  35  5.858156 5.706723 2009
     6.061418  36  5.941249 5.705493 2009
      5.36827  37  5.605112 5.704263 2009
     4.675123  38  5.249549 5.703033 2009
     5.486053  39  5.382829 5.701803 2009
     5.773736  40  5.710765 5.700572 2009
     6.379871  41  5.616705 5.699343 2009
     5.591414  42  5.552283 5.698112 2009
     5.927886  43  5.789228 5.696882 2009
     6.233268  44  5.957685 5.695652 2009
     6.233268  45  5.883868 5.694422 2009
     6.368409  46  5.905463 5.693192 2010
     5.916423  47  5.837501 5.691962 2010
     5.842315  48  5.920594 5.690732 2010
     5.675261  49  5.584457 5.689502 2010
     5.474591  50  5.228894 5.688272 2010
     5.474591  51  5.362175 5.687042 2010
     5.223276  52   5.69011 5.685812 2010
     6.049955  53  5.596051 5.684582 2010
     5.762273  54  5.531628 5.683352 2010
     5.356808  55  5.768574 5.682122 2010
     5.356808  56  5.937031 5.680892 2010
     5.675261  57  5.863213 5.679662 2010
      5.47245  58         .        . 2011
     5.914283  59         .        . 2011
      5.47245  60         .        . 2011
      4.66152  61  4.945485 5.009988 2011
     4.373838  62 4.5899224 5.008758 2011
      4.66152  63  4.723202 5.007528 2011
      4.66152  64  5.051137 5.006298 2011
     5.354667  65  4.957078 5.005068 2011
     4.884664  66  4.892656 5.003838 2011
     5.066985  67  5.129601 5.002607 2011
     5.354667  68  5.298059 5.001378 2011
      4.66152  69  5.224241 5.000147 2011
     5.211245  70  5.245836 4.998917 2012
     5.462559  71  5.177874 4.997687 2012
     5.462559  72  5.260967 4.996457 2012
     4.874772  73   4.92483 4.995227 2012
    3.9584816  74 4.5692673 4.993997 2012
    4.3639464  75  4.702547 4.992767 2012
     5.344776  76  5.030483 4.991537 2012
    4.3639464  77  4.936423 4.990307 2012
    3.9584816  78  4.872001 4.989077 2012
     4.874772  79  5.108947 4.987847 2012
     5.973384  80  5.277404 4.986617 2012
    4.6516285  81  5.203586 4.985387 2012
     5.354535  82  5.225181 4.984157 2013
     4.661388  83  5.157219 4.982926 2013
     4.884531  84  5.240312 4.981697 2013
     5.066853  85  4.904175 4.980466 2013
     4.884531  86 4.5486126 4.979236 2013
     5.066853  87 4.6818924 4.978006 2013
     5.066853  88  5.009828 4.976776 2013
     4.373706  89  4.915769 4.975546 2013
     5.221004  90  4.851346 4.974316 2013
     5.066853  91  5.088292 4.973086 2013
     5.672989  92  5.256749 4.971856 2013
     3.968241  93  5.182931 4.970626 2013
     5.230325  94  5.204526 4.969396 2014
        5.587  95  5.136564 4.968166 2014
      5.68231  96  5.219657 4.966936 2014
     4.893853  97   4.88352 4.965705 2014
     4.893853  98 4.5279574 4.964476 2014
        5.587  99 4.6612372 4.963245 2014
     5.363856 100  4.989173 4.962015 2014
     4.670709 101  4.895113 4.960785 2014
     4.383027 102  4.830691 4.959555 2014
     4.893853 103  5.067636 4.958325 2014
     5.076174 104  5.236094 4.957095 2014
     5.230325 105  5.162276 4.955865 2014
     5.072777 106  5.183871 4.954635 2015
    3.9741645 107  5.115909 4.953405 2015
    3.9741645 108  5.199002 4.952175 2015
     5.678913 109  4.862865 4.950945 2015
    4.6673117 110 4.5073023 4.949715 2015
     5.360459 111 4.6405826 4.948485 2015
     5.478242 112  4.968518 4.947255 2015
     5.226927 113  4.874459 4.946024 2015
    4.6673117 114  4.810036 4.944795 2015
     5.226927 115  5.046982 4.943564 2015
     5.072777 116  5.215439 4.942334 2015
     5.360459 117  5.141621 4.941104 2015
    4.6959615 118  5.163216 4.939874 2016
     5.794574 119  5.095254 4.938644 2016
    4.0028143 120  5.178347 4.937414 2016
    4.6959615 121   4.84221 4.936184 2016
    4.0028143 122 4.4866476 4.934954 2016
     3.309667 123 4.6199274 4.933724 2016
     5.101427 124  4.947863 4.932494 2016
    4.4082794 125  4.853804 4.931264 2016
    4.4082794 126  4.789382 4.930034 2016
     5.874617 127  5.026327 4.928803 2016
     4.919105 128  5.194784 4.927574 2016
     3.309667 129  5.120966 4.926343 2016
     4.405113 130  5.142561 4.925114 2017
            . 131  5.074599 4.923883 2017
     4.915939 132  5.157692 4.922653 2017
      5.09826 133  4.821555 4.921423 2017
     4.915939 134 4.4659925 4.920193 2017
     4.915939 135 4.5992727 4.918963 2017
            . 136  4.927208 4.917733 2017
     3.999648 137  4.833149 4.916503 2017
            . 138  4.768726 4.915273 2017
            . 139  5.005672 4.914043 2017
     3.999648 140  5.174129 4.912813 2017
     5.252411 141  5.100311 4.911583 2017
     4.687375 142  5.121906 4.910353 2018
     4.910519 143  5.053944 4.909122 2018
      5.86603 144  5.137037 4.907893 2018
     5.380522 145    4.8009 4.906662 2018
     4.910519 146  4.445338 4.905432 2018
     4.687375 147 4.5786176 4.904202 2018
     5.380522 148  4.906553 4.902972 2018
     4.399693 149  4.812494 4.901742 2018
     4.399693 150 4.7480717 4.900512 2018
     4.687375 151  4.985017 4.899282 2018
     4.687375 152  5.153474 4.898052 2018
      5.09284 153  5.079656 4.896822 2018
    4.4040904 154  5.101252 4.895592 2019
     5.703373 155  5.033289 4.894362 2019
    4.6917725 156  5.116383 4.893132 2019
     4.914916 157  4.780245 4.891901 2019
     3.998625 158 4.4246826 4.890672 2019
    4.4040904 159  4.557963 4.889441 2019
    4.6917725 160  4.885898 4.888212 2019
      5.38492 161  4.791839 4.886981 2019
    4.4040904 162 4.7274165 4.885751 2019
     5.251389 163  4.964362 4.884521 2019
     5.502703 164  5.132819 4.883291 2019
     4.914916 165  5.059001 4.882061 2019
    end
    ------------------ copy up to and including the previous line ------------------

    Listed 165 out of 165 observations

    Comment


    • #3
      Any help?

      Comment


      • #4
        Dear Fredrick,

        I have superficially changed your code to create the plot to improve reading (putting the more general graph options first above the more specific options that deal with ticks, labels, etc.):
        Code:
        set scheme s2color
        twoway (scatter lograte time if time, msize(vsmall) xline(57, lpattern(shortdash) lwidth(thin) lcolor(black)) ///
        xline(61, lpattern(shortdash) lwidth(thin) lcolor(black))) ///
            (line pred_withseason time if time<58,lcolor(green)) (line pred_withseason time if time>60,lcolor(green)) ///
            (line pred_withoutseason time if time<58, lwidth(thin) lcolor(cranberry)) ///
            (line pred_withoutseason time if time>60, lwidth(thin) lcolor(cranberry)), ///
            graphregion(color(white))  xsize(9) ysize(5) /// plotregion(margin(zero))
            title("{bf:radiologically-defined pneumonia 2-59 months}", size(small)) ///
            yscale(titlegap(*6)) xscale(titlegap(*6)) ///
            ylab(3.91 "50" 4.61 "100" 5.30 "200" 5.99 "400" 6.40 "600", angle(hor) labsize(vsmall) nogrid) ///
            xtitle("Years", size(small)) ytitle("Incidence rates per 100,000 person-years(log{subscript:10}scale)", size(small)) ///
            bgcolor(white) legend(position(2) cols(1) size(vsmall) order(1 2 4) symxsize(2) lab(1 "Monthly incidence") ///
            lab(2 "Temporal trend and season") lab(4 "Temporal trend") width(26) region(lcolor(white))) ///
            xlab(5 "2006" 15.5 "2007" 27.5 "2008" 39.5 "2009" 51.5 "2010" 63.5 "2011" 75.5 "2012" 87.5 "2013" 99.5 "2014" 111.5 "2015" 123.5 "2016" ///
            135.5 "2017" 147.5 "2018" 159.5 "2019", noticks labsize(vsmall)) ///
            xtick(0 9 21 33 45 57 69 81 93 105 117 129 141 153 165)
        Note that I have excluded your option code
        Code:
        plotregion(margin(zero))
        which renders the result that you are looking for:
        Click image for larger version

Name:	meeting x and y axis at zero.png
Views:	1
Size:	132.4 KB
ID:	1732282

        I did not search for any alternative or inspected the possible consequences of my version of your code.
        http://publicationslist.org/eric.melse

        Comment


        • #5
          As an incidental detail note that the y axis scale is logarithmic scale on any base of logarithms. You would see the same labels and same spacing Stata used natural logarithms, base 2 logarithms, or logarithms to any base. In fact I'd guess that Stata uses natural logarithms internally, but as said that's immaterial.

          Comment

          Working...
          X