Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Problem encountered when trying to shade an area on a graph


From   Scott Merryman <scott.merryman@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Problem encountered when trying to shade an area on a graph
Date   Sun, 13 May 2012 13:18:45 -0500

You can -scatteri , recast(line)- to superimpose a line on top of
other graph elements:


graph twoway ///
                        (scatteri 2 -2 2 3.33, recast(area)
fcolor(gs14) lcolor(gs14)) ///
                        (scatteri 0.5 0, mcolor(black) msymbol(O)
msize(vlarge)) ///
                        (pci 0.5 2.5 0.5 0, lcolor(black) lwidth(medthick)) ///
                        (pci 0.45 2.5 0.55 2.5, lcolor(black)
lwidth(medthick)) ///
                        (scatteri 1.5 -0.1, mcolor(black) msymbol(O)
msize(vlarge)) ///
                        (pci 1.5 1.7 1.5 -0.1, lcolor(black)
lwidth(medthick)) ///
                        (pci 1.45 1.7 1.55 1.7, lcolor(black)
lwidth(medthick)) ///
			(scatteri 0 3.33  2 3.33 , recast(line) lpattern(dash) )  ///
			(scatteri 0 0 2 0, recast(line) ) ///
       , xscale(range(-2 5)) xlabel(-2(1)5)  ///
       xtitle("Difference", margin(0 0 0 4)) ///
       xtick(-2(0.5)5) ///
       ysize(1) xsize(1.5) ///
       yscale(range(0 2)) ylabel("") legend(off) ///
       text(1.9 3.8 "{&Delta} = 3.33 mg", size(small)) ///
       text(1.65 1.7 "1.7", size(small)) ///
       text(0.65 2.5 "2.5", size(small)) ///
       plotregion(margin(zero))


Scott

On Sun, May 13, 2012 at 10:29 AM, Philip Jones
<pjones.statalist@gmail.com> wrote:
> Dear Statalisters,
>
> I am encountering a problem when I try to add shading to a graph using
> code. The graph is in the context of a non-inferiority trial, and is
> meant to show point estimates and one-sided CIs. I am attempting to
> create a rectangular grey-shaded area to a graph constructed using
> immediate twoway commands using the advice found at
> http://www.stata.com/statalist/archive/2003-06/msg00121.html, but
> unfortunately, when I create the shading, two vertical lines I would
> like superimposed on the graph (using --xline--) are obscured. I would
> like to know how to "un-obscure" them.
>
> Perhaps it is better shown by using my specific example. Below is the
> code necessary to create the graph I want, sans shading, and should
> run fine without any dataset:
>
> -------------------------------------
>
> set scheme lean1
>
> graph twoway ///
>                         (scatteri 0.5 0, mcolor(black) msymbol(O) msize(vlarge)) ///
>                         (pci 0.5 2.5 0.5 0, lcolor(black) lwidth(medthick)) ///
>                         (pci 0.45 2.5 0.55 2.5, lcolor(black) lwidth(medthick)) ///
>                         (scatteri 1.5 -0.1, mcolor(black) msymbol(O) msize(vlarge)) ///
>                         (pci 1.5 1.7 1.5 -0.1, lcolor(black) lwidth(medthick)) ///
>                         (pci 1.45 1.7 1.55 1.7, lcolor(black) lwidth(medthick)) ///
>        , xscale(range(-2 5)) xlabel(-2(1)5)  ///
>        xtitle("Difference", margin(0 0 0 4)) xline(3.33, lpattern(dash)
> lcolor(black)) ///
>        xline(0, lcolor(black)) xtick(-2(0.5)5) ///
>        ysize(1) xsize(1.5) ///
>        yscale(range(0 2)) ylabel("") legend(off) ///
>        text(1.9 3.8 "{&Delta} = 3.33 mg", size(small)) ///
>        text(1.65 1.7 "1.7", size(small)) ///
>        text(0.65 2.5 "2.5", size(small)) ///
>        plotregion(margin(zero))
>
> -------------------------------------
>
> As you can see, there are two vertical lines added, one at "0" and
> another at "3.33".
>
> When I try to shade, this is what I get:
>
> -------------------------------------
> set scheme lean1
>
> // horizontal graph
> graph twoway ///
>                         (scatteri 2 -2 2 3.33, recast(area) fcolor(gs14) lcolor(gs14)) ///
>                         (scatteri 0.5 0, mcolor(black) msymbol(O) msize(vlarge)) ///
>                         (pci 0.5 2.5 0.5 0, lcolor(black) lwidth(medthick)) ///
>                         (pci 0.45 2.5 0.55 2.5, lcolor(black) lwidth(medthick)) ///
>                         (scatteri 1.5 -0.1, mcolor(black) msymbol(O) msize(vlarge)) ///
>                         (pci 1.5 1.7 1.5 -0.1, lcolor(black) lwidth(medthick)) ///
>                         (pci 1.45 1.7 1.55 1.7, lcolor(black) lwidth(medthick)) ///
>        , xscale(range(-2 5)) xlabel(-2(1)5)  ///
>        xtitle("Difference", margin(0 0 0 4)) xline(3.33, lpattern(dash)
> lcolor(black)) ///
>        xline(0, lcolor(black)) xtick(-2(0.5)5) ///
>        ysize(1) xsize(1.5) ///
>        yscale(range(0 2)) ylabel("") legend(off) ///
>        text(1.9 3.8 "{&Delta} = 3.33 mg", size(small)) ///
>        text(1.65 1.7 "1.7", size(small)) ///
>        text(0.65 2.5 "2.5", size(small)) ///
>        plotregion(margin(zero))
>
> -------------------------------------
>
> Where the two vertical lines are obscured. I suspect this is related
> to the order in which graph elements are drawn, which I tried to
> overcome by drawing the grey area first, but clearly this is not
> sufficient.
>
> Can anyone tell me why the --xline-- lines are being drawn underneath
> the grey-shaded area, and, more importantly, how I can overcome this
> issue?
>
> Many thanks!
>
> Phil
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index