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: Suppress labeling of categorical axis values in graph bar/hbar
From
Eric Booth <[email protected]>
To
"<[email protected]>" <[email protected]>
Subject
Re: st: Suppress labeling of categorical axis values in graph bar/hbar
Date
Sat, 18 Dec 2010 22:31:51 +0000
<>
I think that working with the relabel option is your best bet. You can automate
the creation of the relabel() expression with a loop, but normally I'd suggest
building it in a local macro , but I couldn't get the local to store the double
quotes for use in the relabel option.
Here's some examples of things I tried:
***!
sysuse auto, clear
forval n = 1/`=_N' {
loc la1 `la1' `"`n' " " "'
loc la2 `la2' "`n' " " "
loc la3 `la3' `n' `" "'
loc la4 `"`la4' `n' " "'"'
}
forval n = 1/4 {
di in y as smcl "`n' {hline}"
di in g "`la`n''"
}
***!
Anyone have an idea of how to store the double quotes in a local to pass to the
relabel option?
Since using the local didn't work for me, here's a less straightforward solution
using a couple of string variables (which are limited to 244 chars) to do essentially
the same thing:
***********!
sysuse auto, clear
foreach v in "1/15" "16/30" "31/45" "46/60" "61/74" {
**get variable name**
loc varname `v'
loc varname: subinstr local varname `"/"' "", all
**create "o" vars with relabel option**
g o`varname' = ""
forval n = `v' {
if !inlist(`n', 1, 20, 40, 60 , 74) ///
replace o`varname' = o`varname' + `" `n' " " "'
if inlist(`n', 1, 20, 40, 60 , 74) ///
replace o`varname' = o`varname' + `" `n' "`=make[`n']' ""'
}
}
ds o* //<-- Here's the new vars for relabel()
graph hbar (asis) price, bargap(10) ///
over(make, relabel(`=o115' ///
`=o1630' `=o3145' `=o4660' `=o6174') ///
label(angle(horizontal) labsize(vsmall) labgap(5)))
***********!
After kludging all this together, it might be more work than typing out
the relabel() for 74 obs in the auto.dta; however, it would be useful
for much larger datasets. (However, you can't get too much larger
before the bars become indistinguishable.)
- Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754
Fax: +979.845.0249
http://ppri.tamu.edu
On Dec 18, 2010, at 3:13 PM, Davide Cantoni wrote:
> Hello,
>
> I would like to draw a bar chart displaying the values of a given
> variable for all the observations in the dataset. However, since there
> are many observations, I would like to label only some of them (some
> representative cases). Conceptually, this is similar to this working
> example:
>
> *** begin example
> sysuse auto, clear
> graph hbar (asis) price, over(make, sort(price))
> *** end example
>
> As you can see, putting all the labels on the categorical axis leads
> to overcrowding. What I would like to do is to label only some
> representative examples, e.g. only "Renault Le Car", "VW Diesel" and,
> say, "Lincoln Versailles". I guess I can achieve the suppression of
> labels with some relabel() command inside the over() parenthesis, but
> given the large number of observations, this would be incredibly
> cumbersome. Any other suggestions?
>
> Thanks in advance,
>
> Davide
> *
> * 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/