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: determine coordinates of bars in graph automatically?
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: determine coordinates of bars in graph automatically?
Date
Fri, 25 May 2012 13:35:00 +0100
Here is a start. (I don't follow you in showing mean car prices to
fractions of a dollar precision, but your real example will be
different.)
sysuse auto
local Y "`: var label price'"
local X1 "`: var label rep78'"
local X2 "`: var label foreign'"
collapse (mean) price if !missing(foreign, rep78), by(foreign rep78)
gen x = rep78 + cond(foreign, 0.2, -0.2)
gen text = string(price, "%4.0f")
twoway bar price x if !foreign, barw(0.4) || bar price x if foreign ,
barw(0.4) ///
base(0) yla(0(2000)6000) ytitle("`Y' (USD)") xtitle("`X1' and `X2'")
legend(order(1 "Domestic" 2 "Foreign")) ///
|| scatter price x, ms(i) mla(text) mlabcol(white) mlabpos(6)
This approach is tedious at first, because you have to work out how to
copy stuff that -graph bar- does for you. But now you have coordinates
for adding any text you like.
Nick
On Fri, May 25, 2012 at 1:06 PM, Kaulisch, Marc
<[email protected]> wrote:
> Excuse me for not specifying my question correctly. I hardly use twoway bar so I was not thinking about this option.
>
> My example looks like:
> sysuse auto
> graph bar price, over(foreign) over(rep78, label( alternate)) asyvars ///
> blabel(total, position(inside) format(%9,1f) color(white) size(small)) ///
> bargap(0)
>
> I do not know how to convert it into a twoway bar and getting rep78 (by(rep78)) to appear in one graph...
>
> Best regards,
>
> Marc
>
> -----Ursprüngliche Nachricht-----
> Von: [email protected] [mailto:[email protected]] Im Auftrag von Nick Cox
> Gesendet: Freitag, 25. Mai 2012 13:16
> An: [email protected]
> Betreff: Re: st: determine coordinates of bars in graph automatically?
>
> I take it that this is a question about -graph bar-, not -twoway bar-.
>
> One answer is that this kind of control is much easier in -twoway bar-. How helpful that is depends on how close your graphs are to those that can be produced in -twoway bar-.
>
> Nick
>
> On Fri, May 25, 2012 at 11:27 AM, Kaulisch, Marc <[email protected]> wrote:
>> I would like to know if there is a way to determine the coordinates of
>> a bar graph automatically?
>>
>> I would like to add text to the base of each bar (similar to the base
>> option in blabel), but it is very time consuming to open a type of
>> graph and to determine the coordinates manually. Additionally, I would
>> like to add another text below the total which is located inside the bar.
>>
>> So basically, I would like to get access to the coordinates Stata
>> uses, when blabel is placed inside and on the base. Any ideas how get there?
>>
>> As a feature request, it would great if text added to a bar graph
>> could use the blabel options.
> *
> * 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/
*
* 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/