Announcement

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

  • Color two areas of the histogram

    Hi,

    I am trying to colour two areas of the histogram, currently I am only able to colour one of the areas. The code I currently have is:

    histogram income if income < 6, start(0) width(0.5) lcolor(orange) freq fcolor(orange*0.2) addplot(histogram income if income > 6, start(6) width(0.5) freq lcolor(blue) fcolor(blue*0.2)) legend(order(1 "Outliers") ring(0) pos(1)) graphregion(fcolor(white)) xtitle("Logarithm of income", size(medsmall))



    But I want to colour the area above 15 too also in orange.

    Thank you in advance
    Last edited by Enrique Alameda; 18 Apr 2023, 08:47.

  • #2
    Help please

    Comment


    • #3
      There is no data example here. But here is some technique.

      Code:
      sysuse auto, clear 
      
      set scheme s1color 
      
      twoway__histogram_gen mpg, start(10) width(2) gen(density MPG) 
      
      twoway bar density MPG if MPG < 20, barw(2) lcolor(red) fcolor(red*0.2) ///
           || bar density MPG if inrange(MPG, 20, 30), barw(2) lcolor(black) fcolor(white) ///
           || bar density MPG if MPG > 30, barw(2) lcolor(blue) fcolor(blue*0.2) ///
           xtitle("`: var label mpg'") legend(off)
      Click image for larger version

Name:	density.png
Views:	1
Size:	14.2 KB
ID:	1710369

      Comment


      • #4
        Thank you very much, your solution worked flawlessly.

        Comment

        Working...
        X