Hi,
I'm trying to create a histogram that flags height values outside of an indicated range as red, and values within that range as green. My thought was to use the twoway function and plot two separate histograms on top of one another (one for the 'in-range' values, and one for the 'out-of-range' values). However, because the N's are different for each it throws off the bar sizes (and percentages) making the plot look odd. Is there anyway to maintain the same N for twoway plots so the scaling is consistent? I've attached some sample code below:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input double bs041 80 82 85 87.5 89 89.5 95.3 95.5 100.7 101 101 105 105 113 113.7 117 120.6 120.8 120.8 122.4 123 125 125.9 126 126.7 127 127 130 130 131 132 132 132 132 132 132 132 132 132 132.1 132.6 132.7 133 133.7 134 134 134 134 134 134 134 134.6 135 135 135 135 135 135 135.3 135.4 135.6 135.6 135.7 135.7 136 136 136 136.9 136.9 137.5 137.7 138 138 138.9 139.5 140 140 140.2 140.6 140.7 141 142 142 142 142 142 142 142 142 142 142 142 142.1 142.3 142.7 143 143 143 143 143 end
Code:
histogram bs041, percent color(grey%30) xlabel(50(50)250) ylabel(, angle(0)) xline(125 220, lcolor(black)) text(40 172.5 "Height Range (125-220 cm)")
Code:
twoway histogram bs041 if (bs041 >= 125 & bs041 <= 220), percent color(green%30) || histogram bs041 if (bs041 < 125 | bs041 > 220), percent color(red%30) xlabel(50(50)250) ylabel(, angle(0)) xline(125 220, lcolor(black)) text(40 172.5 "Height Range (125-220 cm)")
Thanks!
David
Comment