Announcement

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

  • Histogram x-axis does not start flush at 0

    Hello all,
    I am trying to create a histogram where the x-axis starts exactly at 0, with the first bin touching the y-axis. However, even when the first bin clearly starts at 0, Stata leaves visible space between the y-axis and x = 0. Please see example screenshot below after I input:

    histogram Pubs, width(100)
    (bin=8, start=0, width=100)

    Click image for larger version

Name:	pubshistogram.png
Views:	1
Size:	48.6 KB
ID:	1783993

    Is there a way to force the x-axis to start exactly at 0 (i.e., eliminate this left-side gap), or is this behavior inherent to how histogram scales axes in Stata?

    Thank you,
    Ola

  • #2
    This has come up before in the forum, and I made the point that this behavior appears to be a default of histogram, but not of twoway histogram, which addresses this. Consider:

    Code:
    sysuse auto, clear
    qui sum weight
    gen cweight= weight- r(min)
    
    hist cweight, title(Histogram: Default) saving(gr1, replace)
    tw hist cweight, title(Twoway Histogram: Default) saving(gr2, replace)
    tw hist cweight, plotregion(margin(zero)) title(Twoway Histogram: Adjusted) saving(gr3, replace)
    gr combine gr1.gph gr2.gph gr3.gph
    Res.:
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	41.0 KB
ID:	1783998




    Last edited by Andrew Musau; 29 Dec 2025, 13:38.

    Comment

    Working...
    X