Announcement

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

  • Adding title to graphs already in memory

    Hi,

    I have a do-file that generates a very large number of plots in a systematic fashion (say 100+), kind of like here:

    Code:
    sysuse auto, clear
    
    foreach x of varlist price rep78 headroom trunk weight length turn {
      twoway scatter mpg `x', name(fig_`x', replace)
    }
    After generating all these graphs, I look at them and combine a number of them (in the dozens) to use them as figures in my report:

    Code:
    graph combine fig_price fig_length, col(2) name(fig1, replace)
    The problem with this figure is of course that the two panels of the figure aren't labeled, what I would want to have is something like:

    Code:
    twoway scatter mpg price, name(fig_price, replace) title(A, justification(left) bexpand) nodraw
    twoway scatter mpg length, name(fig_length, replace) title(B, justification(left) bexpand) nodraw
    graph combine fig_price fig_length, col(2) name(fig1_fixed, replace)
    But making the plots anew doesn't strike me as optimal.

    My question now is: Is there a way to add this title() to the graphs already in memory? I have a feeling that there might be a way to do it with gr_edit, but I don't know where to find that out.

    Thank you so much
    NB

  • #2
    Dear Nora,

    Actually, I think you are not doing so bad 'making the plots anew', if it is just the titles that you want to add.
    The alternative would be to code the graph editor changes, but that might be just as much effort to do, if not more.
    And the result might be not that attractive:

    Code:
    sysuse auto, clear
    
    foreach x of varlist price rep78 headroom trunk weight length turn {
      twoway scatter mpg `x', name(fig_`x', replace)
    }
    
    graph combine fig_price fig_length, col(2) name(fig1, replace)
    gr_edit title.style.editstyle box_alignment(west) editcopy
    gr_edit title.text.Arrpush A                                               B
    How to generate the code for graph editor changes is explained by me here [#6] and by Scott Merryman here {#4].

    Possibly, someone else on the Statalist knows of a more smart solution.

    Best,
    Eric
    http://publicationslist.org/eric.melse

    Comment


    • #3
      Following the same approach as Eric using gr_edit, it seems possible to include graph-specific titles in the combined graph ex post.

      Code:
      sysuse auto, clear
      foreach x of varlist price rep78 headroom trunk weight length turn {
        twoway scatter mpg `x', name(fig_`x', replace)
      }
      graph combine fig_price fig_length fig_weight fig_turn, col(2) name(fig1, replace)
      
      local titles "A B C D"
      forval i=1/4{
         gr_edit .plotregion1.graph`i'.title.text.Arrpush "`:word `i' of `titles''"
         gr_edit .plotregion1.graph`i'.title.DragBy .1619603027199639 -24.29404540800029
      }
      Res.:

      Click image for larger version

Name:	fig1.png
Views:	1
Size:	58.6 KB
ID:	1547402

      Comment


      • #4
        See also crossplot and combineplot from SSC as discussed at

        https://www.statalist.org/forums/for...ailable-on-ssc

        https://www.statalist.org/forums/for...ailable-on-ssc

        Andrew's graph in #3 can be obtained with


        Code:
        sysuse auto, clear
        
        crossplot mpg (price weight length turn), sequence(A B C D)

        Comment


        • #5
          Hi, I am working on a scatter plot on expenditure among insured uninsured and my commands look this:

          graph twoway (scatter oopinsuredhh state_new if direction==0, mcolor(red) msymbol(circle) msize(small)) (scatter oopinsuredhh state_new if direction==1, mcolor(green) msymbol(s) msize(small)) (scatter oopuninsuredhh state_new if direction==0, mcolor(red) msymbol(circle) msize(small)) (scatter oopuninsuredhh state_new if direction==1, mcolor(green) msymbol(s) msize(small)) (pcarrow oopuninsuredhh state_new oopinsuredhh state_new if direction==0, lcolor(red) mcolor(red) mfcolor(green) mlcolor(red)) (pcarrow oopuninsuredhh state_new oopinsuredhh state_new if direction==1, lcolor(green) mfcolor(green) mlcolor(green) mcolor(green))


          This gives me the desired result but there are two problems that I am facing
          1. The y and x axis bot start from 0 , I just want a common 0 with some space between state name on horizontal axis and y axis (I don't know how to insert outergap in the above command.
          2. How should I construct states in descending order in the graph based on uninsured value

          Thanks in advance!

          Comment


          • #6
            #5 was repeated at https://www.statalist.org/forums/for...ith-directions I suggest that anybody wanting to follow go there to post or to read any answers.

            Comment

            Working...
            X