Announcement

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

  • Shaded bar between values of X axis of a line graph

    Hi,

    I am making a line graph where x axis is the year. I want to highlight/shade the periods between 2007-2009 and 2016-2018 respectively. I used the area in twoway line graph but it shades only the area under the line. How can I highlight years?

    My code:
    Code:
    twoway (line unique year, by(type) xline(2007 2009 2016 2018)) ///
    (area unique year if year>=2007 & year<=2009 & year>=2016 & year<=2018)
    Thanks

    I found one reference image online:

    Click image for larger version

Name:	IMG-20200323-WA0009.jpg
Views:	1
Size:	81.2 KB
ID:	1543472
    Last edited by Kedar Kelkar; 29 Mar 2020, 05:33.

  • #2
    Your condition

    Code:
     
     year>=2007 & year<=2009 & year>=2016 & year<=2018
    is never going be to satisfied as no year in 2007, 2008, 2009 is ever equal to any of 2016, 2017, 2018, and vice versa.

    I think you need

    Code:
     
     (year>=2007 & year<=2009) |  (year>=2016 & year<=2018)
    and I suggest that

    Code:
    inrange(year, 2007, 2009) | inrange(year, 2016, 2018)
    is easier to work with.

    Comment

    Working...
    X