Announcement

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

  • Position of added text in legend

    Text can be added to a legend with a dash followed by text in quotes. The position of this added text can be changed with the Graph Editor. Is it possible to control the position of the added text with a Stata command? I found no option for this in the Stata help file or documentation.

    In the example below I would like to move the added text to the left margin of the box, so that it is placed above the two lines in the legend, not the words "Life expectancy".

    Code:
    sysuse uslifeexp
    line le_female year || line le_male year, legend(col(1) order(- "This text should be moved left" 1 2))

  • #2
    What if you used the title() option instead?

    Code:
     
     line le_female year || line le_male year, legend(col(1) title("This text should be moved left", size(medium) pos(11)))

    Comment


    • #3
      Thank you for the suggestion. I cannot use the title() option because I have more than one line of added text in the legend. Sorry I didn't make that clear in my initial post. Below is a revised example.

      Code:
      sysuse uslifeexp
      
      line le_female year || line le_male year, ///
        legend(col(1) order(- "This text should be moved left" 1 ///
         - "This text should also be moved left" 2))

      Comment


      • #4
        The closest I can get is use the textfirst option which puts the symbols on the right side.

        Maybe if you tell us more, we could consider a wider range of solutions.

        Comment


        • #5
          I was looking for a way to have all text left-aligned. The text is not left-aligned when the textfirst option is used.

          Code:
          line le_female year || line le_male year, ///
            legend(col(1) order(- "This text should be moved left" 1 ///
            - "This text should also be moved left" 2) textfirst)
          I can obtain the desired effect with gr_edit, which requires experimentation in the Graph Editor. Moving the text this way also requires adjustment of the border around the legend. Below is the command I am using now but I would have preferred to make use of documented commands. gr_edit is not documented.

          Code:
          line le_female year || line le_male year, ///
            legend(col(1) order(- "This text should be moved left" 1 ///
            - "This text should also be moved left" 2) ///
            region(margin(1 -17 1 1)))
          
          gr_edit .legend.plotregion1.label[1].DragBy 0 -15.2
          gr_edit .legend.plotregion1.label[3].DragBy 0 -15.2

          Comment


          • #6
            Hello friends, I wanted to arrange options following a command in a vertical way. Stata considers some options as commands and says they are not recognized, how can I do that. please see the example.
            graph bar (mean) tempjan tempjuly, over(region) ///
            legend(label(1 "July") label(2 "January"))
            bargap(-30)
            ytitle("Degress Farenheit")
            title("Month of the Year")
            title ("Average June and July Temperatures")

            Stata says legend is not a command

            Thanks

            Comment

            Working...
            X