Box Plot1

Boxplot over groups of three categorical variables. Special coding features include the use of SMCL in graph titles, the automation of axes labels, and the use of special ASCII characters using the _char() function in the `di:' operator.



#delimit ;
sysuse auto, clear ;

generate wp = (weight/price>=0.5) if !missing(weight,price) ;

local pr_min = round(r(min)/1000)*1000 ;
local pr_max = round(r(max)/1000)*1000 ;

graph hbox price, 
      over(wp) over(rep78, gap(*2) label(labsize(*.85)) total)
      over(foreign, gap(*1.5) label(labsize(*.85)) )
      box(1, lwidth(*.75))
      box(2, lwidth(*.75))
      ylabel(`pr_min'(1000)`pr_max', angle(60) labsize(*.75))
      legend(cols(1) pos(5) ring(0) size(*.75) symxsize(*.5) 
                  label(1 "W/P `:di _char(179)' 0.5")
                  label(2 "W/P < 0.5"))
      title("The price of cars in 1978", size(*.8) color(dknavy))
      note("{it: Note}: W/P indicates Weight to Price ratio.")
      xsize(8) ysize(5)
      graphregion(lcolor(gs0)) plotregion(lcolor(gs0))
      saving(price_box.gph, replace) ;

 graph export price_box.pdf, replace ;