Announcement

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

  • How to force vertical lines to be above of all horizontal lines using twoway

    Dear all,

    How do I force the gray area to be above the yellow areas in the graph below?

    Code:
    clear
    set obs 100
    gene x = runiform()
    gene y = runiform()
    twoway (scatter x y), xline(0.5(0.001)0.6, lcolor(black*0.25))  yline(1(0.001)2 0.5(0.001)0.6, lcolor(gold*0.40))
    I have been searching for similar questions, but the closest one was this one:

    https://stackoverflow.com/questions/...ots-in-a-graph

    Any suggestions? Perhaps more efficient ways to create the shaded area?

    All the best,

    Tiago
    Last edited by Tiago Pereira; 30 Jul 2021, 09:38.

  • #2
    Code:
    clear
    set obs 100
    gene x = runiform()
    gene y = runiform()
    twoway scatter x y ||  scatteri 1 1 1 0, recast(area) base(1.1) color(gold*0.40) ||scatteri .6 1 .6 0,  recast(area) base(.5) color(gold*0.40)  ||scatteri 1.1 .5 1.1 .6, recast(area) base(0) color(black*0.25)  || , ysc(r(0 1.1))  legend(off)

    Comment


    • #3
      Thank you, Ali.
      That's very close to what I need to implement in Stata.

      I understand that elegant way. What if my code is actually more complex? E.g., an arbitrary number of shaded areas on the y axis?

      Do you envisage how to automatize it?

      Code:
      clear set obs 100
      gene x = runiform()*10
      gene y = runiform()*100
      twoway (scatter x y), xline(5(0.01)6, lcolor(black*0.25)) yline(10(0.001)20 30(0.001)40 50(0.001)60 70(0.001)80 90(0.001)100, lcolor(gold*0.40))
      Thank you so much again.

      All the best,

      Tiago

      Comment


      • #4
        Code:
        clear
        set obs 100
        gene x = runiform(0,10)
        gene y = runiform(0,100)
        forv x = 10(20)90{
            local scatteri `scatteri'scatteri `x' 10 `x' 0, base(`=`x'+10') recast(area) color(gold*0.40)||
        }
        twoway scatter y x || `scatteri' scatteri 100 5 100 6, recast(area) base(0) color(black*0.25) ||, ysc(r(0 1.1))  legend(off)

        Comment


        • #5
          Thank you so much, Ali. Extremely helpful. That's amazing.

          All the best,
          Tiago

          Comment

          Working...
          X