Announcement

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

  • How to label point of intersection of X and Y in bar graph

    Dear Statalist users

    While preparing the bar graph, I want to label the point of intersection of X and Y (origin) in the bar graph as the first entry of the date variable (Starting Date) which is 25feb2022, and at last/end of the x-axis as the last date which is 22mar2022.

    Data is

    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long site1 float(date week1)
    1 22701 1
    1 22720 4
    1 22714 3
    1 22715 3
    1 22715 3
    1 22715 3
    1 22718 4
    1 22718 4
    1 22720 4
    1 22720 4
    1 22725 5
    1 22726 5
    3 22722 4
    3 22726 5
    2 22719 4
    2 22720 4
    2 22721 4
    2 22721 4
    end
    format %td date
    label values site1 site
    label def site 1 "A", modify
    label def site 2 "B", modify
    label def site 3 "C", modify

    The code I have used is

    graph hbar (count), over(site1) over(week1) bar(1, fcolor(navy)) blabel(bar) ytitle(Count) title("My Name is Manoj") xlabel(min(date1) max(date))
    but it showing me error

    Anticipating your help as always


    Ashish




  • #2
    As the help explains

    graph hbar draws horizontal bar charts. In a horizontal bar chart, the numerical axis is still called the y
    axis, and the categorical axis is still called the x axis, but y is presented horizontally, and x
    vertically.
    This paper may help

    SJ-21-1 gr0086 Stata tip 140: Shorter or fewer category labels with graph bar
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
    Q1/21 SJ 21(1):263--271 (no commands)
    tip on fixing categorical axis labels

    Something like this is more flexible:

    Code:
    bysort site1 week1 : gen count = _n 
    
    twoway bar count week1, by(site1, note("")) xla(1/5) base(0) barw(0.8)

    Comment


    • #3
      Hi Nick,
      Thank you for prompt help, but, twoway bar does not solve my purpose. The expected graph is for reference. I don't know why xtitle does not work work in bar command.which I think can solve my purpose.

      Thanks
      Attached Files

      Comment

      Working...
      X