I am plotting actual and predicted rates of an event and want to emphasize times when actual exceeded predicted and vice versa. I've attached data and the code to create two graphs that aren't exactly what I want.
In the first version, there is no change in shading color.
In the second version, the shading color changes, but the shaded region doesn't exactly match the shape of the area between the lines.
I'm probably not the first to want to do this--has anyone developed a method to make it work?
In the first version, there is no change in shading color.
In the second version, the shading color changes, but the shaded region doesn't exactly match the shape of the area between the lines.
I'm probably not the first to want to do this--has anyone developed a method to make it work?
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float dt double(actual predicted) 21915 .3469639850779763 .28161612542707887 21922 .33249606101521084 .2823371799191069 21929 .31045343211196497 .28269158152852114 21936 .2859349142080523 .2890576291187378 21943 .2689252093502894 .3050486616517073 21950 .2594151983932902 .3231018050827308 21957 .23873048698868282 .33936473298506314 21964 .21008050332694667 .33601787184519843 21971 .20156126392584633 .3111580381318348 21978 .22863544297280752 .28395028536352795 21985 .2660472141141334 .26082748481494766 21992 .29655574434967535 .25953957681502066 21999 .31047023493071646 .2769737081770453 22006 .30256011879759714 .29519669922777303 22013 .31316367479107704 .3105154315846261 22020 .33034560075873415 .3158314224579599 22027 .3423353364338891 .31421121409660363 22034 .3255514845029689 .31123034641138675 22041 .33064063113656567 .30797980257571406 22048 .3440255688837501 .3050228966236359 22055 .3880894232632907 .30628983645919167 22062 .45888253150535363 .313261414441176 22069 .45787862165242454 .3214246624527872 22076 .4258455243912937 .32874556554942996 22083 .37023067043414676 .3313199710417261 22090 .3380617836034539 .33069423801440934 end format %td dt /* V1: no change in shading */ twoway (rarea actual predicted dt, fcolor(gs12) lcolor(none)) /// (line actual dt, lpattern(dash) lwidth(thick)) /// (line predicted dt, lpattern(solid) lwidth(thick)) /* V2: change in shading, but with gaps */ gen pos=actual>predicted sort dt gen change=pos!=pos[_n-1] gen area=sum(change) twoway (rarea actual predicted dt if area==1, fcolor(gs12) ) /// (rarea actual predicted dt if area==2, fcolor(gs1) ) /// (rarea actual predicted dt if area==3, fcolor(gs12) ) /// (line actual dt, lpattern(dash) lwidth(thick)) /// (line predicted dt, lpattern(solid) lwidth(thick)), legend(off)
Comment