Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | Re: st: Selecting only certain labels for categorical variable in bar graph |
Date | Tue, 18 Mar 2014 13:13:17 +0000 |
To see what the problem is, I faked it with a data set with the same number of years and notional countries. clear set obs 430 egen year = seq(), from(1970) to(2012) block(10) egen country = seq(), to(10) gen stuff = exp(rnormal()) My understanding is that -graph bar- and its siblings are geared to plotting data for known categories, all of which you are presumed to care about. I tried various tricks to suppress category detail, or reduce it, but the only one I can recommend is using value labels to hold two-digit years. (-graph bar- does not seem to pay attention to numeric display formats. The -relabel()- suboption just seemed to mess things up.) forval y=1970/2012 { local year : di %02.0f mod(`y', 100) label def year `y' `year', modify } label val year year graph bar (asis) stuff, over(country) over(year, label(labsize(vsmall))) /// asyvars stack legend(on size(small) col(4) symysize(1) symxsize(3)) That's a little tight, but it looks better than what you had. Note the detail "(asis)". The only other suggestion is that you recast this as a problem for -twoway rbar-, but you are going to need to do some work to get the stacking. All that said, I wouldn't choose stacked bars for displaying this kind of data. You have ten time series and I would go for some kind of line plot. Your question, edited: "is there a good website that lists all the commands that can be used with -over()-?" By commands here, I guess you mean suboptions, and I don't think anything will be more comprehensive than the manual entry. Nick njcoxstata@gmail.com On 18 March 2014 10:25, Gilad Isaacs <222521@soas.ac.uk> wrote: > Hi, > > First, thanks to Nick for answering a previous question of mine (I > don't know how to respond to that particular thread). > > I am graphing a stacked bar graph of panel data, it is for the years > 1970 - 2012, and it is the foreign exchange reserves for 10 countries. > I've done the following: > > xtset year > > graph bar reserve_per_world_GDP, over(countryname) over(year, > label(labsize(small) angle(60))) asyvars stack legend(on size(small) > col(4) symysize(1) symxsize(3)) > > It all works fine. However, the year labels: 1970, 1971, 1972 etc. on > the "x" axis, i.e. for the categorical variable "year", are > overlapping with one another. I'd like to be able to able to display > only every second year, like with a normal graph which would use > xlabel(1970(2)2012), or to space the bars further apart. If such a > option exists I'm sure it goes in the over(year...) command but I > don't know what the command is. > > (Even if I make the year labels vertical, i.e. angle(90), they still > touch each other) > > Also, is there a good website that lists all the commands that can be > used with "over"? > > Thanks! > > Gilad > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/