Announcement

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

  • Yline over graph and not behind

    Hi,

    I'm trying to make a very basic graph bar with an yline. See the code below for a reproducible example:

    Code:
        sysuse auto
        dataex make price mpg rep78 in 1/5
        graph bar price, over(foreign) yline(4000, lcolor(red))
    Here is the graph I get :
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	22.0 KB
ID:	1725572

    I want the yline to be over the bars, not behind it. I've tried adjusting the opacity, but it doesn't work.

    Any idea?
    Last edited by Marine Jouvin; 31 Aug 2023, 02:49.

  • #2
    It's a matter of Stata graphics principles that added lines are always laid down before any data elements.

    One way to get round this is to do something quite different.

    How closely your example is related to what you really want to do only you can say, but although it seems a small difference cosmetically, your problem calls for quite different code, unless I am missing a simple trick. Consider

    Code:
    sysuse auto, clear
    egen mean_price = mean(price), by(foreign)
    twoway bar mean_price foreign, xla(0 1, valuelabel) base(0) barw(0.6) || function 4000, range(-0.4 1.4) lcolor(red) legend(off) yla(0(1000)7000) ytitle(Mean price (USD))
    Last edited by Nick Cox; 31 Aug 2023, 03:12.

    Comment

    Working...
    X