Announcement

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

  • Graph legend

    Greetings,
    I am trying to create a graph legend that includes labels above the keys, like this:


    Click image for larger version

Name:	g2.png
Views:	2
Size:	130.0 KB
ID:	1305934



    Currently I need to use the graph editor to achieve it; I begin with

    Code:
    gr twoway connected mpg price if foreign || ///
         connected mpg price if !foreign || ///
         connected weight price if foreign || ///
         connected weight price if !foreign , ///
         legend( ///
            order(- "foreign" - "domestic" 1 "Mileage" 2 "" 3 "Weight" 4 "") ///
            size(vsmall) colgap(vsmall) keygap(vsmall) just(center)///
         )
    Which produces this:

    Click image for larger version

Name:	g1.png
Views:	1
Size:	129.8 KB
ID:	1305935

    Then I use the Graph editor in grid edit mode to move the words "foreign" and "domestic" into the right columns, and to resize them.

    I realize that I probably can't get those labels in a different size through the command line, but I wonder if there is a way to get them placed right?

    Thanks for any thoughts!

    FWIW, the .grec file created by my edit has this:

    Code:
    StataFileTM:00001:01100:GREC:                          :
    00004:00004:00001:
    *! classname: twowaygraph_g
    *! family: twoway
    *! date: 12 Aug 2015
    *! time: 13:26:57
    *! graph_scheme: n1mono
    *! naturallywhite: 1
    *! end
    
    // File created by Graph Editor Recorder.
    // Edit only if you know what you are doing.
    
    .legend.plotregion1.move label[1] on 5 1
    // label[1] grid reposition
    
    .legend.plotregion1.move label[2] on 5 5
    // label[2] grid reposition
    
    .legend.plotregion1.label[2].style.editstyle box_alignment(center) editcopy
    // label[2] compass position
    
    .legend.plotregion1.label[2].style.editstyle size(small) editcopy
    // label[2] size
    
    .legend.plotregion1.label[1].style.editstyle size(small) editcopy
    // label[1] size
    
    .legend.plotregion1.label[1].style.editstyle box_alignment(center) editcopy
    // label[1] compass position
    
    
    // <end>
    Attached Files

  • #2
    Nicholas,
    Code:
    do http://www.radyakin.org/statalist/2015/20150812-1305932.do
    produces the graph with the labels shifted.
    Best, Sergiy Radyakin

    Comment


    • #3
      Though I think it would be easier just to use your .grec file and graph play, another way would be to use the legend title options

      Code:
      gr twoway connected mpg price if foreign || ///
           connected mpg price if !foreign || ///
           connected weight price if foreign || ///
           connected weight price if !foreign  ///
           || , legend(   /// 
              order(  1 "Mileage" 2 "" 3 "Weight" 4 ""  ) ///
              size(vsmall) colgap(vsmall) keygap(vsmall) just(center) /// 
              subtitle( "Domestic                     Foreign", size(*.65) ) /// 
              )

      Comment


      • #4
        Thank you both for the suggestions. Sergiy - that works, but the results don't survive -graph save-, -clear-, -graph use-. Scott: I played with that, but ended up deciding it was easier to -graph play- than to fiddle each time with the spacing on the title.

        Comment

        Working...
        X