Announcement

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

  • Shifts when laying multiple histograms

    Hi,

    I would like to generate one histogram which have three graphs covering on the others. The three graphs were supposed to cover the earlier graphs if they locate at the same position. However, some bars were placed perfectly, some were not with some shifting. For example, there were two blue bars (around May 2016 and May 2018) on the same date of the red/ gray bars and the very small shifting of blue made them show some red color behind. In other situations, some blue bars (e.g., 1/3) could cover perfectly and some (e.g., 2/3) could not.

    All the numbers and values are just from made-up data for clarifying my questions.

    The syntax for the 1st combined histogram is listed here:
    twoway ///
    (histogram date if (outcome==3 | outcome ==2 | outcome ==1), disc freq fcolor(gray) lcolor(black) lwidth(vvthin) width(8) gap(0) ) || ///
    (histogram date if (outcome==3 | outcome ==2), disc freq fcolor(blue) lcolor(black) lwidth(vvthin) width(8) gap(0) ) || ///
    (histogram date if (outcome==3 ), disc freq fcolor(red) lcolor(black) lwidth(vvthin) width(8) gap(0) ) ///
    , ///
    ylab(1(1)5) xtitle("First Diagnosis Date") xmtick(`minday0'(30)`maxday0') ytitle("Number of Cases") ///
    xlabel(`minday0'(60)`maxday0', format(%d) labsize(small) angle(45)) ///
    legend(label (1 "All Cases") label(2 "Car Related") label(3 "Bike Related") pos(6)) plotregion(margin(zero)) ///
    title("Count Curve, N=2") subtitle("Summarized cases dates from: `minday1' to `maxday1'") note("Chart Produced: `c_date'")

    I have spent several days on this and could not figure out why some are good while some are not in one graph. I would appreciate any help you could offer. Thank you very much.

    Xuan
    Click image for larger version

Name:	1.PNG
Views:	1
Size:	50.2 KB
ID:	1496902
    Click image for larger version

Name:	2.PNG
Views:	1
Size:	45.4 KB
ID:	1496903
    Click image for larger version

Name:	3.PNG
Views:	1
Size:	45.5 KB
ID:	1496904
    Click image for larger version

Name:	4.PNG
Views:	1
Size:	42.1 KB
ID:	1496905
    Attached Files

  • #2
    Does anyone could help? The similar codes are fine when running other data files. Once the x-axis turned to dates, the issue piped up.

    Many many thanks in advance.

    Comment


    • #3
      Hi Xuan,

      I'm guessing you no longer need help on this. If you are still working on it, have you tried changing width(8) to barwidth(8)? I am not the best at Stata but I also had this problem and this fixed it for me.

      Best,

      Chrissy

      Comment

      Working...
      X