Announcement

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

  • Changing a density figure to get bars side by side instead of overlaying one another

    Hello,

    I have a density plot below, using the code below. Is there a way to adjust the code so that the blue and grey bars are side by side instead of overlaying one another? And by side by side I mean grey blue grey blue grey blue, not all greys and then all blues.

    TIA -
    CJ
    Code:
    *AFST score distribution: using score on first referral
    twoway histogram afst_score1 if screenedin==0, color(blue%60) || histogram afst_score1 if screenedin==1, percent title(AFST Score) legend(label (1 Screened Out)) legend(label(2 Screened In)) xtitle(AFST Score) ytitle(Density) graphregion(color(white)) xlabel(1 (1) 20) color(black%30)
    Click image for larger version

Name:	afst.png
Views:	1
Size:	59.7 KB
ID:	1681312

  • #2
    Perhaps something like this?

    Code:
    sysuse nlsw88, clear
    
    twoway__histogram_gen grade if south==0, percent gen(h0 x0) discrete
    twoway__histogram_gen grade if south==1, percent gen(h1 x1) discrete
    
    replace x0 = x0 - 0.2
    replace x1 = x1 + 0.2
    
    #delimit ;
    twoway     bar h0 x0, color(blue%60) barwidth(0.4) ||
            bar h1 x1, color(black%30) barwidth(0.4)
            xlabel(1 (1) 20)
            title(AFST Score)
            legend(label (1 Screened Out))
            legend(label(2 Screened In))
            xtitle(AFST Score)
            ytitle(Density)
            graphregion(color(white))
            scheme(scolor2)
            ;
    #delimit cr
    Which produces this:
    Click image for larger version

Name:	Screenshot 2022-09-09 at 9.48.40 PM.png
Views:	1
Size:	124.4 KB
ID:	1681326

    Last edited by Hemanshu Kumar; 09 Sep 2022, 10:19.

    Comment


    • #3
      I tried and it says that the command twoway_histogram_gen is not recognized. Where does this command come from and how do I install it? Couldn't see to find. Thanks!

      Comment


      • #4
        Oh wait, wait!! Two underscores. Thank you so much

        Comment

        Working...
        X