Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • graph combine: Label rows and columns

    I'm combining 4 graphs using -graph combine-. I'd like to label the rows and columns of the combined graph -- is there a way?
    For example, in the -graph combine- statement at the end of the following code, I'd like to have label the columns "Pre-COVID" and "Post-COVID" and I'd like to label the rows "Nonpoor children" and "Poor children".
    Suggestions welcome!

    Code:
    global effect_size = -0.2
    global mean_nonpoor_pre = 0
    global mean_poor_pre = invnormal(.21)
    global mean_nonpoor_post = $mean_nonpoor_pre + $effect_size
    global mean_poor_post = $mean_poor_pre + $effect_size
    
    global common_options xline(0) xscale(range(-4 3)) xtitle("") ytitle("") xlabel(none) ylabel(none)
    
    local left = $mean_nonpoor_pre-3
    local right = $mean_nonpoor_pre+3
    graph twoway (function y=normalden(x,$mean_nonpoor_pre,1), range(`left' `right') lw(thick)), $common_options saving(nonpoor_pre, replace)
    local left = $mean_poor_pre-3
    local right = $mean_poor_pre+3
    graph twoway (function y=normalden(x,$mean_poor_post,1), range(`left' `right') lw(thin)), $common_options saving(poor_pre, replace)
    
    local left = $mean_nonpoor_post-3
    local right = $mean_nonpoor_post+3
    graph twoway (function y=normalden(x,$mean_nonpoor_post,1), range(`left' `right') lw(thick)), $common_options saving(nonpoor_post, replace)
    local left = $mean_poor_post-3
    local right = $mean_poor_post+3
    graph twoway (function y=normalden(x,$mean_poor_post,1), range(`left' `right') lw(thin)), $common_options saving(poor_post, replace)
    
    graph combine nonpoor_pre.gph poor_pre.gph nonpoor_post.gph poor_post.gph

  • #2
    HI Paul,
    Without seeing how you have combined your graphs it is somewhat difficult to answer your question - can you upload an image of the combined graph?
    It sounds like you might want some of the functionality offered by - grc1leg2 - from SSC. This allows you to have a single title covering multiple graph axes, and more.
    If you upload a png of the combined graph I should be able to provide a more concrete solution.
    Best,
    Matt
    Last edited by Matthew Alexander; 03 Jan 2022, 17:55.

    Comment


    • #3
      Actually I think you require the t2title and l2title options of graph twoway (prior to graph combine).
      For nonpoor_pre:
      Code:
      t2title("Pre-Covid") l2title("Nonpoor children")
      For poor_pre:
      Code:
      l2title("Poor children")
      For nonpoor_post:
      Code:
      t2title("Post-Covid")
      And then neither title is needed for poor_post.
      Last edited by Matthew Alexander; 03 Jan 2022, 19:16.

      Comment


      • #4
        paulvonhippel , if I understand correctly, Matthew Alexander 's post #3 would work as a way to specify row and column titles.

        But you might be able to accomplish what you want by simply deploying Stata's graph twoway command with a -by- option like this:

        Code:
        sysuse auto, clear
        gen expensive = price > 6165
        label def expensive 0 Cheap 1 Expensive
        label values expensive expensive
        tab expensive foreign
        
        *    You can use the -by()- option with two variables such as your
        *    "Pre-COVID" and "Post-COVID" crossed against "Nonpoor children" and "Poor children" like this:
        
        twoway scatter mpg length weight , by(expensive foreign) name(norowcoltitles, replace)
        
        *    By using appropriate options you can move the category titles to the left side and the top like this:
        
        twoway scatter turn mpg weight ,   ///
            subtitle("")  ///
            by(expensive foreign,  ///
                l1title("Expensive             Cheap")    ///  
                t1title("Domestic                          Foreign")  )  ///
                name(withrowcoltitles, replace)
        An advantage of the above approach is that Stata provides a single legend for the composite four-panel graph.

        But if your four panel graphs for the four categories defined by "Pre-COVID" and "Post-COVID" crossed against "Nonpoor children" and "Poor children" cannot be created by a single -twoway ... , by(covid poor)- command and you would like to attach a single legend to the four-panel graph, perhaps -grc1leg2- might still be useful. See especially Examples 3.6 and 3.10 in the help file.

        -grc1leg2- is not from SSC, but instead from the Stata site maintained by the Center for Global Development. In any case, since Stata's web crawler seems to locate all the Stata sites on the web and index them for its -search- command, you can find, describe and install -grc1leg2- from inside Stata by typing:

        Code:
        search grc1leg2
        Last edited by Mead Over; 07 Feb 2022, 12:51.

        Comment

        Working...
        X