Announcement

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

  • Adding a horizontal line to an hbar – It's possible in Graph Editor; how to do it programmatically?

    I run this:
    Code:
    sysuse auto, clear
    graph hbar price, over(foreign)
    Using Graph Editor, I can add a reference line like this:
    Click image for larger version

Name:	Screen Shot 2017-07-01 at 10.39.32 PM.png
Views:	1
Size:	653.1 KB
ID:	1400086


    I want to add that line using my do-file. I tried this:
    Code:
    graph hbar price, over(foreign) yline(50)
    That resulted in this:
    Click image for larger version

Name:	Screen Shot 2017-07-01 at 10.40.05 PM.png
Views:	1
Size:	373.2 KB
ID:	1400087

    So I tried
    Code:
    graph hbar price, over(foreign) xline(50)
    which gave the error
    Code:
    xlines(50) not allowed, xaxis1 does not exist
    How do I add a horizontal line in my do-file, instead of using Graph Editor?

  • #2
    Unfortunately, I fail to see the point of doing so, unless for other reasons apart from the core function of a hbar graph itself.

    This is what we get from the Stata Manual:

    yline() adds horizontal (bar) or vertical (hbar) lines at specified y values; see [G-3] added line options. The xline() option, also documented there, is irrelevant for bar charts.
    Best regards,

    Marcos

    Comment


    • #3
      You could use -twoway- to get this. Example:

      Code:
      sysuse auto, clear
      
      collapse (mean) price, by(for)
      
      twoway (bar price for, sort barwidth(.5) horiz),  yline(.5, lwidth(vthick)  lpattern(tight_dot)) ylabel(0(1)1, valuelabel)
      Eric A. Booth | Senior Director of Research | Far Harbor | Austin TX

      Comment


      • #4
        Originally posted by Nils Enevoldsen View Post
        How do I add a horizontal line in my do-file, instead of using Graph Editor?
        Any change in the Graph Editor can be incorporated in a do-file. See this post for more information: https://www.statalist.org/forums/for...r-graph-panels

        Comment


        • #5
          Thanks, all! Friedrich, that's excellent general-purpose advice. I will remember this.

          Comment

          Working...
          X