Announcement

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

  • Basic question on how to draw a vertical line that splits the distribution in a histogram

    Hi all
    I am stuck in a basic procedure with histograms and hope someone can help.

    I used the following code to prepare a histogram for scaled profit that is higher than -0.3 and lower than 0.3:
    Code:
    hist profit if profit>-0.3 & profit<0.3, width(0.0025) freq
    How can I draw a vertical line that comes from zero and hence split the distribution in the histogram ?

  • #2
    Add the option

    Code:
    xline(0)
    Note that your command doesn't ensure that 0 will be a bin limit, so

    Code:
     hist profit if profit>-0.3 & profit<0.3, width(0.0025) freq xline(0) start(-0.3)
    .
    seems indicated.

    Comment


    • #3
      Thanks Nick.
      When I added what you suggest, I successfully get the line I want. However, it seems to be behind the bars. Can I make this line on the bars and not behind them?

      Comment


      • #4
        Indeed; the intent of added lines is to be reference lines and not be plotted on top of data. For technique to get what you want, you can run and study the effects of


        Code:
        sysuse auto, clear
        histogram mpg, width(1) freq addplot(scatteri 0 25 10 25, recast(line) lw(medthick)) yla(0(2)10) legend(off) bfcolor(blue*0.1) blcolor(blue)

        Comment

        Working...
        X