Announcement

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

  • Histogram - adjusting the start of the x axis

    Hello everyone! I am creating an epidemic curve using the histogram function. I have successfully created a graph, however there is a space (gap) between the 1st bin (dated 26sep2021) and the y axis. I'd like the 1st bin to start at 0 (no gap). I tried using the xscale(range option but it does not seem to work. I am using Stata version 14.2 on Windows 10. Any insights? Thank you!

    Code:
    histogram date_onset, bin(17) frequency fcolor(dknavy) lcolor(dknavy) lpattern(blank) ytitle(No. of Cases) ytitle(, orientation(horizontal)) ylabel(, angle(horizontal) nogrid) xtitle(Date of Onset) xlabel(#17, format(%tdDD)) graphregion(margin(large) fcolor(white))
    For additional information, the earliest Date of Onset is 26sep2021 and last date is 15nov2021. I just used the DD for the x-axis tick labels because I will be adding a text box under the dates to indicate the month (and move the Date of Onset x axis label lower).
    Click image for larger version

Name:	Screenshot 2022-03-03 105605.png
Views:	1
Size:	13.3 KB
ID:	1652767


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte age str6 sex float date_onset
    49 "male"   22549
    71 "male"   22551
    15 "female" 22552
    58 "female" 22552
    22 "male"   22552
    22 "male"   22552
     1 "male"   22552
    30 "female" 22552
    25 "male"   22552
     5 "male"   22553
    12 "female" 22553
    33 "male"   22554
    28 "male"   22554
    82 "female" 22554
    20 "male"   22554
    10 "male"   22554
    21 "female" 22554
    21 "female" 22554
    12 "female" 22554
    23 "female" 22554
    end
    format %td date_onset
    Last edited by Ian Gonzales; 02 Mar 2022, 21:11.

  • #2
    Use an extra option

    plotregion(margin(zero))

    Comment


    • #3
      Originally posted by Nick Cox View Post
      Use an extra option

      plotregion(margin(zero))
      Thank you, Nick! That managed to narrow the gap. I played around with the margin some more and figured out the custom margin. If set to (-5 0 0 0), the gap will close, albeit with a small overlap of the 1st bin to the y-axis. All the best!

      Code:
      histogram date_onset, bin(17) frequency fcolor(dknavy) lcolor(dknavy) ///
      lpattern(blank) ytitle(No. of Cases) ytitle(, orientation(horizontal)) ///
      ylabel(, angle(horizontal) nogrid) xtitle(Date of Onset) ///
      xlabel(#17, format(%tdDD)) graphregion(margin(large) fcolor(white)) ///
      plotregion(margin(-5 0 0 0))
      Attached Files
      Last edited by Ian Gonzales; 03 Mar 2022, 02:15.

      Comment

      Working...
      X