Announcement

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

  • twoway graphs with different yaxis

    Hello I am trying to do a graph with two different yaxis. The problem is that the difference between labels in the yaxis is different for the two axis even though the two axis are specified to have 10 unit spaces across labels.
    This is the code I use:

    ​​​​​​twoway bar fac_summ group, barwidth(0.8) fintensity(20) lcolor(navy) yscale(alt) || scatter chmtr0706 group, yaxis(2) lpattern(dash) connect(direct) msymbol(circle) mcolor(navy) lcolor(navy) yscale(alt axis(2)) ytitle("Fraction of personal income taxpayers (in %)", height(4) orientation(rvertical)) ylabel(0(10)50, nogrid) title({bf:2006 Reform: 2007-2006 difference}, size(medium) color(black)) xlabel(1 "0-4" 2 "4-14" 3 "14-26" 4 "26-46" 5 ">46") xtitle("Net taxable income in 2006 (in thousands of €)", height(4.5)) ytitle("Mechanical change in marginal net of tax rate" "on financial income (in %)", height(7) axis(2)) yline(0, axis(2) lcolor(cranberry) lwidth(thin)) yline(-10 -20 -30 -40 -50, axis(2) lcolor(black) lpattern(dot) lwidth(thin)) legend(order(2 "Mechanical change in marginal net of tax rate" 1 "Fraction of personal income taxpayers") rows(2)) graphregion(color(white))

    I would like to have 0 in the left axis at the same level than 50 in the right axis. Can anyone help me with this?
    Thank you very much.
    Attached Files

  • #2
    Can you provide a data example using dataex?

    Comment


    • #3
      Thank you very much for your answer

      This is the exact data I am using

      group chmtr0706 fac_summ
      1 3.5289565 26.723615
      2 -7.8950947 22.418532
      3 -13.889589 16.655305
      4 -30.15873 11.446494
      5 -49.090909 14.66789

      Comment


      • #4
        Interesting! Put your data and code in [CODE] may raise chance of attention and reply.
        Code:
        ​​​​​​clear
        input group chmtr0706 fac_summ
        1 3.5289565 26.723615
        2 -7.8950947 22.418532
        3 -13.889589 16.655305
        4 -30.15873 11.446494
        5 -49.090909 14.66789
        end
        
        twoway bar fac_summ group, barwidth(0.8) fintensity(20) lcolor(navy) yscale(alt) || scatter chmtr0706 group, yaxis(2) lpattern(dash) connect(direct) msymbol(circle) mcolor(navy) lcolor(navy) yscale(alt axis(2)) ytitle("Fraction of personal income taxpayers (in %)", height(4) orientation(rvertical)) ylabel(0(10)50, nogrid) title({bf:2006 Reform: 2007-2006 difference}, size(medium) color(black)) xlabel(1 "0-4" 2 "4-14" 3 "14-26" 4 "26-46" 5 ">46") xtitle("Net taxable income in 2006 (in thousands of €)", height(4.5)) ytitle("Mechanical change in marginal net of tax rate" "on financial income (in %)", height(7) axis(2)) yline(0, axis(2) lcolor(cranberry) lwidth(thin)) yline(-10 -20 -30 -40 -50, axis(2) lcolor(black) lpattern(dot) lwidth(thin)) legend(order(2 "Mechanical change in marginal net of tax rate" 1 "Fraction of personal income taxpayers") rows(2)) graphregion(color(white))
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	93.6 KB
ID:	1510425

        Comment


        • #5
          Thanks for the data example. The right hand side axis just reflects your assigned labels - 10=0, ..., 50=30 (if you remove the line in red below)

          ​​​​​​twoway bar fac_summ group, barwidth(0.8) fintensity(20) lcolor(navy) yscale(alt) || scatter chmtr0706 group, yaxis(2) lpattern(dash) connect(direct) msymbol(circle) mcolor(navy) lcolor(navy) yscale(alt axis(2)) ytitle("Fraction of personal income taxpayers (in %)", height(4) orientation(rvertical)) ylabel(0(10)50, nogrid) title({bf:2006 Reform: 2007-2006 difference}, size(medium) color(black)) xlabel(1 "0-4" 2 "4-14" 3 "14-26" 4 "26-46" 5 ">46") xtitle("Net taxable income in 2006 (in thousands of €)", height(4.5)) ytitle("Mechanical change in marginal net of tax rate" "on financial income (in %)", height(7) axis(2)) yline(0, axis(2) lcolor(cranberry) lwidth(thin)) yline(-10 -20 -30 -40 -50, axis(2) lcolor(black) lpattern(dot) lwidth(thin)) legend(order(2 "Mechanical change in marginal net of tax rate" 1 "Fraction of personal income taxpayers") rows(2)) graphregion(color(white))
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	169.6 KB
ID:	1510432




          Do you simply want to relabel the right-hand side axis such that you have "50" where the red line touches it or you want to rescale one of the graphs?
          Last edited by Andrew Musau; 01 Aug 2019, 10:37.

          Comment


          • #6
            Thanks for the answer, I want to relabel the right-hand side axis such that I have "50" where the red line touches it, I have tried with the range command but I am not able to move the "50" down to where the red line is .

            Comment


            • #7
              Looks like a simple extension of the -ylabel- upper limit is required. With

              Code:
              ylabel(0(10)53.5, nogrid)
              I get

              Click image for larger version

Name:	Graph.png
Views:	1
Size:	95.5 KB
ID:	1510493

              Comment


              • #8
                See multiline from SSC for an alternative to this awkward design. The command name gives you a search term for examples in this forum.

                Comment


                • #9
                  Thank you very much for the help, problem solved!!

                  Comment


                  • #10
                    Hello again,
                    I want to do a similar plot but with different values and when I put instead of 50, different values such as 53.4, 55, etc. in the axis, I do not manage to have the 50 exactly at the level of the red line. Can anyone help?

                    group chmtr0706 fac_summ
                    1 3.5294118 4.5159493
                    2 -7.8954369 7.5888007
                    3 -13.888889 12.299763
                    4 -30.15873 17.434183
                    5 -49.090909 57.684914


                    twoway bar fac_summ group, barwidth(0.8) fintensity(20) lcolor(navy) yscale(alt) || scatter chmtr0706 group, yaxis(2) lpattern(dash) connect(direct) msymbol(circle) mcolor(navy) lcolor(navy) yscale(alt axis(2)) ytitle("Fraction of personal income taxpayers (in %)", height(3) orientation(rvertical) size(medsmall)) ylabel(0(10)50, nogrid) title("{bf:2007 REFORM: 2007-2006 DIFFERENCE}" "{bf:WEALTH TAXPAYERS (2004-2006)}", size(small) color(black)) xlabel(1 "0-4" 2 "4-14" 3 "14-26" 4 "26-46" 5 ">46") xtitle("Net taxable income in 2006 (in thousands of €)", height(4.5) size(medsmall)) ytitle("Mechanical change in marginal net of tax rate" "on financial income (in %)", height(7) axis(2) size(medsmall)) yline(0, axis(2) lcolor(cranberry) lwidth(thin)) yline(-10 -20 -30 -40 -50, axis(2) lcolor(gs14) lwidth(thin)) legend(order(2 "Mechanical change in marginal net of tax rate" 1 "Fraction of personal income taxpayers") rows(2)) graphregion(color(white))

                    Thank you very much in advance.

                    Comment


                    • #11
                      Your upper limit for your second variable is at \(\approx\) 57.7, so you will want to manipulate both axes. Something like

                      Code:
                      ylabel(0(10)53.5, nogrid) ylabel(-50(10)7.75, nogrid axis(2))

                      Comment


                      • #12
                        Thank you, if I put ylabel(-50(10)7.75, nogrid axis(2)) the 50 lies exactly at the red line but on the left-hand side the axis goes up to 60 even when specifying 7.75. Is there a way to omit the 60 as label and tick?
                        Thank you very much!

                        Comment


                        • #13
                          Code:
                          ylabel(-50(10)0 7.75 " ", notick nogrid axis(2)) ytick(-50(10)0, axis(2))

                          Comment


                          • #14
                            Thank you very much Andrew. One last thing, with the option you suggest the ytick on axis(2) overlaps with the ylabel. Is there a way to leave a small space between the ylabel numbers from the ytick as in axis(1)?

                            Comment


                            • #15
                              Replace

                              Code:
                              ylabel(-50(10)0 7.75 " ", notick nogrid axis(2))
                              with

                              Code:
                              ylabel(-50(10)0 7.75 " ", tstyle(major_notick) nogrid axis(2))

                              Comment

                              Working...
                              X