Combining charts

You can combine separate Stata graphs into one graph by using -combine-. We will illustrate how this works using census.dta included in Stata. (The not-so-neat) Figure 1 below is the combination of three separate graphs. How was Figure 1 created?

sysuse census.dta

/* First, create separate graphs and and store each of them into memory by using the name() option. Note that name() and saving() options are two different things. saving() saves the graph permanently (of course, until you erase it!) into a disk, while name() temporarily saves the graph into memory. */

/*-nodraw- supresses the display of the individual graphs. */

graph bar marriage, over(region) title({bf:A}, size(huge) ring(0) pos(1)) name(panela, replace) nodraw

tw scatter marriage divorce, title({bf:B}, size(huge) ring(0) pos(1))  name(panelb, replace) nodraw

graph hbar pop, over(state2) title({bf:C}, size(huge) ring(0) pos(1)) name(panelc, replace) nodraw

/* Now, we combine the graphs. */

graph combine panela panelb, cols(1)

/* We can also change the number of columns or add an overall title for the combined graph… */

graph combine panela panelb, cols(2) title(“Senseless Graphs“)

/* …or overall y- and x- axis titles. The code below draws figure 1. */

graph combine panela panelb panelc, cols(2) l1title(“Left-side title”) b1title(“Bottom title”) title(“This is Figure 1”)

/* There are other options for combine-, see “help graph_combine”. Also,the x- and y- labels and titles (particularly of panel C in figure 1) can be formatted before they are combined to make them look cleaner and prettier. */