Announcement

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

  • How I could do to coincide in the nivel cero a twoway graph with different scaled and axes?

    Hello!

    I have a tsline graph with different scaled and axes. The left axis has a range (-4,(2) 6) and the right axis has a range (-20(10)30). Both axes pass through the zero, but do not agree on the same level (on the same line). I need that both axes match in the zero, but keeping different scales with the axis.

    I am using the following programming to generate the graph:

    tsline gdp, lwidth(thick) lcolor(midblue) yti("GDP" " ", ///
    height(10) ) || (tsline edu, lwidth(thick) lcolor(orange_red) yaxis(2) ///
    yti(" " "Education", height(10) axis(2) )) in 3/86, ///
    xmtick(##4) xlabel(#22, labsize(vsmall) angle(vertical)) xtitle("", height(9)) ylab(,nogrid) ///
    legend( label(1 "GDP (eje izquierdo)")label(2 "Education (eje derecho)") ///
    label(3 "") label(4 "") order(1 3 2 4) size(medium) region(lwidth(none))) ///
    graphregion(fcolor(white))



    Thanks for your helping


  • #2
    Welcome to Statalist. Because I don't have your data I am going to create a dataset with the same variable names.
    Code:
    webuse idle2, clear
    ren usr gdp
    ren syslcl edu
    tsset time
    Now we can draw a graph. In theory, axes with the ranges -4 to 6 and -20 to 30 have the 0 at the same height, two fifths from the bottom. To make sure that the left and right y-axes are indeed aligned at 0, you have to plot only values within the intended range, and you have to specify the axis labels that you want to appear. The differences between your code in post #1 and the code below are written in red.
    Code:
    tsline gdp if gdp<30, lwidth(thick) lcolor(midblue) yti("GDP" " ", ///
    height(10) ) || (tsline edu if edu<6, lwidth(thick) lcolor(orange_red) yaxis(2) ///
    yti(" " "Education", height(10) axis(2)) ylabel(-4(2)6, axis(2))) in 1/30, ///
    xmtick(##4) xlabel(#22, labsize(vsmall) angle(vertical)) xtitle("", height(9)) ylab(-20(10)30,nogrid) ///
    legend( label(1 "GDP (eje izquierdo)")label(2 "Education (eje derecho)") ///
    label(3 "") label(4 "") order(1 3 2 4) size(medium) region(lwidth(none))) ///
    graphregion(fcolor(white))
    Click image for larger version

Name:	test.png
Views:	1
Size:	11.0 KB
ID:	1329364

    In the future please consider sharing an excerpt from your data so that other list members can test your commands. You can use dataex from SSC to post your data. Please read section 12 in the FAQ for more information.
    Last edited by Friedrich Huebler; 04 Mar 2016, 20:23.

    Comment


    • #3
      Friedrich gives good advice as always. I don't disagree with any of it. In fact, I am not going to attempt the question posed, just to show another way to plot the data. I'll steal his example. You'll need to install sparkline from SSC.

      Code:
      webuse idle2, clear
      set scheme s1color 
      ren usr GDP 
      ren syslcl education 
      sparkline GDP education time, subtitle("") lcolor(red blue) ytitle("") height(0.85) yline(1.5, lcolor(gs12) lw(vvthin))
      Click image for larger version

Name:	friedrich.png
Views:	1
Size:	12.1 KB
ID:	1329368


      For another example, see http://www.statalist.org/forums/foru...hart-correctly

      Comment


      • #4
        Friedrich and Nick your advices are good. Thanks for your helping.

        Comment

        Working...
        X