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. */

2 Responses

  1. There are very simple messages to my mind from your examples, and many similar.

    A 2 X 2 display to me looks good, so if at all possible give the readers 4 graphs if you give them several. You may need to bump up the text size in the individual graphs to keep it legible. (Figure 1C is not defensible any way!)

    A column of 2 graphs to me looks better than a row of 2 graphs. Two histograms or box plots for separate variables offer fair examples. (Histograms or box plots for separate groups you can get with a -by()- option, not -graph combine-.)

    • I agree that there is no excuse for figure 1C given that Stata is so much capable of producing clean and pretty graphs. I will have to show how to clean this graph (and the others as well) in another post.

      Also, I have not tried combining histograms and box plots yet.. I will have to do that exercise and (again) post what I will learn some other time.

      Thanks :)

Leave a Reply