bill999
bill999

Reputation: 2560

graph combine labels for each column and each row

I am using graph combine to combine a number of plots. How can I label each column and each row? In my case, each column graphs a different variable and each row uses a different sample. I would prefer not to have a label for each graph individually as this makes it a lot more cluttered.

An example of what I would like can be found here.

I have looked in the documentation, but did not find a solution. I did find this post on Statalist, but the solution there produces just one common title for the entire axis, not separate ones by columns/rows.

Is it possible to manually add text in the spirit of text(x y "text...") to graph combine?

Here is an example:

sysuse uslifeexp, clear

graph drop _all
line le_male year if year<=1950, ytitle("") name(male1900)

line le_female year if year<=1950, ytitle("") name(female1900)

line le_male year if year>1950, ytitle("") name(male1951)

line le_female year if year>1950, ytitle("") name(female1951)

graph combine male1900 female1900 male1951 female1951, rows(2) cols(2)

I would like to label it as follows (with more space on the row labels so that it doesn't spill into the graph; importantly, the label should not be part of the individual small graph, but put onto the combined set of graphs produced by graph combine):

enter image description here

Upvotes: 0

Views: 2316

Answers (2)

Nick Cox
Nick Cox

Reputation: 37358

Another solution is to restructure the data, so that the graph emerges from a call that includes the by() option. The order of the panels is naturally at choice. Once you have the graph, you can edit e.g. graph subtitles.

sysuse uslifeexp, clear

keep le_male le_female year 

gen period = year > 1950
label define period 0 "1901-1950" 1 "1951-1999" 
label val period period 

reshape long le_ , i(year) j(gender) string 

egen panel = group(gender period), label 

label var le "Life expectancy (years)"

set scheme s1color 

line le_ year, by(panel, note("") xrescale imargin(medsmall)) ///
yla(, ang(h)) xlabel(#5) xtitle("") 

enter image description here

See also twby from SSC.

Upvotes: 1

user8682794
user8682794

Reputation:

The following works for me:

sysuse uslifeexp, clear

line le_male year if year<=1950, xlabel("") xtitle("") ytitle("1900-1950", ///
                                 orientation(horizontal)) title(MALE) name(male1900)

line le_female year if year<=1950, xlabel("") xtitle("") ytitle("") ///
                                   title(FEMALE) name(female1900)

line le_male year if year>1950, xlabel("") xtitle("") ytitle("1951-1999", ///
                                orientation(horizontal)) name(male1951)

line le_female year if year>1950, xlabel("") xtitle("") ytitle("") name(female1951)

graph combine male1900 female1900 male1951 female1951, rows(2) cols(2)

enter image description here

Upvotes: 1

Related Questions