Announcement

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

  • Shading between two lines in a graph

    Dear Statalist,

    I'm trying to create a shaded area between the two borders of the confidence interval around TS_HUNT_lln (between lb_i and ub_i). Below is the code I'm using:

    Code:
    twoway (line hr_i lb_i ub_i TS_HUNT_lln, sort lp(l - -)) ///
     if inrange(TS_HUNT_lln, -10,7) , yscale(log) ytitle("Adjusted Hazard Ratio") ///
     xtitle("BMD T-score") ///
     plotregion(style(none)) ///
     yline(1) ///
     ylabel(0.5 1 1.5 2 3, angle(horiz) format(%4.3f)) ///
      legend(off) xlabel(-10(1)7)  name(or_age_mi, replace)
    Could -twoway rarea- be used somehow?

  • #2
    Code:
     twoway  rarea lb_i ub_i TS_HUNT_lln if inrange(TS_HUNT_lln, -10,7), sort astyle(ci)  || ///
    line hr_i TS_HUNT_lln if inrange(TS_HUNT_lln, -10,7) ///
      ,sort lp(l) yscale(log) ytitle("Adjusted Hazard Ratio") ///  xtitle("BMD T-score") ///
     plotregion(style(none)) ///
     yline(1) ///
     ylabel(0.5 1 1.5 2 3, angle(horiz) format(%4.3f)) ///
      legend(off) xlabel(-10(1)7)  name(or_age_mi, replace)
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thank you Maarten! That worked perfectly.
      Do you know how I could bring the yline to front, overlaying the rest of the plot?

      Comment


      • #4
        You can’t do that. Added lines are automatically laid down early. What you can do is add a call to twoway function laying down a line at 1 over the horizontal range of the graph.

        Comment

        Working...
        X