Announcement

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

  • Reference line layer order

    Dear All, is there any way to control the sequence order of drawing a graph (aka z-order), so that the reference line is placed on top of the graph?
    Consider the following example, quite naturally one would expect the line to be on top of the area.

    I have already tried to place an invisible scatter on top and add a refline there, but it seems that Stata first merges all the layers and then sinks the reflines to the very bottom of the z-order.

    I am obviously trying to avoid manual calculation of the coordinates like: twoway area pc n || scatteri 0 30 500000 30, lpattern(--) recast(line)

    Any workarounds for this?

    Thank you, Sergiy Radyakin

    Code:
    clear all
    sysuse auto
    sort price, stable
    generate n=_n
    generate pc=price in 1
    replace pc=price + pc[_n-1] in 2/L
    twoway area pc n, xline(30, lpattern(--))
    Click image for larger version

Name:	refline.png
Views:	1
Size:	55.7 KB
ID:	1565637


  • #2
    tw dropline provides one workaround.

    Code:
    clear all
    sysuse auto
    sort price, stable
    generate n=_n
    generate pc=price in 1
    replace pc=price + pc[_n-1] in 2/L
    gen xline=30
    twoway (area pc n, leg(off)) (dropline pc xline, lpattern(--) ///
    mcolor(none) lcolor(red)), xline(30, lpattern(--) lcolor(red))
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	34.9 KB
ID:	1565641

    Comment


    • #3
      Thank you very much! This is helpful.
      At first I thought that the red part can be simplified somewhat, but upon experimenting see that both parts are necessary.
      Very clever!

      Comment

      Working...
      X