Announcement

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

  • Filling 'hole' with legend when combining uneven number of graphs

    Greetings,

    I'm running Stata 15.1 on OSX. Using the grc1leg command, I've combined 5 different graphs while generating a common legend. However, the legend is positioned under the 5 panels, with the 6th panel left 'blank'. If possible, I'd like to situate the legend in that blank 6th panel. This is what I'm currently looking at:
    Click image for larger version

Name:	graph example.jpeg
Views:	1
Size:	323.7 KB
ID:	1443950


    This is my code:

    Code:
    grc1leg  "/Users/ZG/Documents/NHMS-RESPECT.gph"  "/ZG/Documents/NHMS-
    > SERVICE.gph" "/Users/ZG/Documents/NHMS-STUPID.gph" "/Users/ZG/Documents/NHM
    > S-AFRAID.gph" "/Users/ZG/Documents/NHMS-HARASSED.gph", iscale(*.9)
    Any help will be much appreciated. Thanks!





  • #2
    In the graph editor under Legend Properties on the Advanced tab there is an option for position offset which will move the legend box.

    Code:
    sysuse auto,clear
    
    scatter mpg price, name(gr1,replace)
    scatter weight price, name(gr2, replace)
    scatter length price, name(gr3, replace)
    
    grc1leg gr1 gr2 gr3
    gr_edit legend.xoffset = 35
    gr_edit legend.yoffset = 35

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	36.4 KB
ID:	1443952

    Comment


    • #3
      Thanks! Followup question: 1) How do I adjust the size of the legend? 2) How do I eliminate the empty space at the bottom?
      Click image for larger version

Name:	graph example 2.jpeg
Views:	1
Size:	323.2 KB
ID:	1443958


      Cheers!

      Comment


      • #4
        There are several different options to change the size of various characteristics of the legend but the most direct is to use size() - part of the text box options. To remove to space at the bottom try using the ring(0) option with grc1leg to place the legend within the plotarea. Example:


        Code:
        sysuse auto,clear
        
        scatter mpg trunk length turn disp weight price, legend(size(*.5) col(1)) name(gr1,replace)
        scatter mpg trunk length turn disp weight price, name(gr2, replace) legend(off)
        scatter mpg trunk length turn disp weight price, name(gr3, replace) legend(off)
        
        grc1leg gr1 gr2 gr3, legendfrom(gr1) ring(0) position(4) 
        
        gr_edit legend.xoffset = -15
        gr_edit legend.yoffset = 15
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	46.9 KB
ID:	1443973

        Comment

        Working...
        X