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: plot yline for different values on each sub plot


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: plot yline for different values on each sub plot
Date   Fri, 15 Apr 2011 11:57:32 +0100

I couldn't get the editing approach to work. That just means what it
says: I am not at all familiar with all that the Graph Editor can so.

This code indicates some technique that might help. Most of it just
sets up an example. The key idea is that a different horizontal line
can be drawn for a variable that is constant in each panel. It is not
a -yline()- and is drawn only over the range of the data.

sysuse auto, clear
contract foreign rep78, zero
graph bar (asis) _freq , over(rep78) by(foreign)
egen mean = mean(_freq), by(foreign)
twoway bar  _freq rep78, barw(0.5) xla(1/5) || line mean rep78, by(foreign)

On Fri, Apr 15, 2011 at 10:16 AM, Nick Cox <[email protected]> wrote:
> I don't know an easy way of doing this. You might try plotting all
> four lines in all panels and then deleting three you don't need in the
> Editor. Or you might draw each graph separately and then use -graph
> combine-. Or you might rewrite using -twoway bar-.
>
> Either way, your macro manipulation is not going to work as you
> intend. Stata interprets your
>
> `=    '
>
> stuff precisely once and _before_ the -graph- command gets to work. It
> certainly does not do that separately for each separate graph, and it
> will always interpret a reference to a variable as a reference to its
> value in the first observation.
>
> Of course, wanting a different yline in each panel is a perfectly
> reasonable request, but I think you will need to do it in one of the
> ways mentioned above.
>
> Nick
>
> On Fri, Apr 15, 2011 at 9:56 AM, Timothy Colbourn
> <[email protected]> wrote:
>
>> I have a bar graph plotted 4 times in one for each different arm of the trial I am analysing: by(arm)
>>
>> I have ploted a yline showing the expected number of births in each arm: yline(`=expbirths') which is a reference against the observed births bars plotted for each month (x axis). The problem is that Stata plots the yline on each of the 4 sub plots at the same value - the value for the first sub plot (arm) - rather than at the value for each arm on each subplot. I have tried yline(`=expbirths by(arm)')  but it does the same thing (with no error message - i.e. it essentially ignores the by(arm). The full syntax for the graph is:
>>
>> graph bar (asis) livebirth stillbirth nnd mvital, over(month, label( labsize(vsmall) angle(90))) ///
>>        ylabel(0(50)550, labsize(small) angle(0)) yline(`=expbirths (arm)') ytitle("frequency") ///
>>        by(, title("Births and deaths in each RCT arm", size(small)) note("")) ///
>>        legend(order(1 "Livebirths" 2 "Stillbirths" 3 "Neonatal Deaths" 4 "Maternal Deaths") size(vsmall)) by(arm)
>>
>> Is it possible to plot the yline for each value of expbirths on each subplot?
>

*
*   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