Announcement

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

  • how to customize the location of legend

    I know the way of using position() to customize the location of legend, but sometimes the legend will overlap with the ylabel as shown in picture, so how to make the legend position lower?

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(tenaciousGoalPursuit group)
    2.9 2
    2.1 2
    3.5 2
    2.1 1
    3.9 2
      4 2
    3.4 2
    2.4 1
    3.3 2
    3.2 2
    3.3 1
    3.2 1
    2.2 1
    3.7 1
      4 2
    2.8 1
    2.9 2
    2.8 1
    3.2 2
    3.9 1
    2.8 1
    2.7 1
    3.5 2
    2.9 2
    3.5 2
    2.5 1
    2.6 1
    3.5 1
    3.4 1
    2.8 1
    3.2 2
    3.4 1
    3.3 2
    2.7 1
    2.9 2
    3.1 2
    3.3 1
    2.5 1
    4.5 1
    3.2 1
    4.5 2
    3.5 1
      2 1
    2.1 1
    3.4 2
    2.6 2
    2.6 2
    3.3 2
    2.8 1
    3.5 2
    3.6 1
    3.3 2
      3 2
    3.5 2
    2.5 1
    4.1 2
    2.8 2
    3.1 2
    2.5 1
    3.1 1
    2.9 2
    3.1 2
    3.4 1
    2.6 1
    1.7 1
    3.8 2
    3.3 1
    2.3 1
    3.5 1
    2.3 1
    2.6 1
    2.2 1
    2.7 1
    3.7 1
    2.3 1
    3.2 2
    3.6 2
    3.8 1
    3.8 1
    2.7 1
    3.2 1
    3.5 2
    3.3 1
      4 1
    2.9 2
    3.4 2
    2.4 1
    2.5 2
    2.8 1
      3 1
    3.6 2
    2.2 1
    3.1 1
    2.4 1
    2.9 2
    3.3 1
    3.2 2
    3.4 1
    3.3 1
      3 1
    end
    label values group group
    twoway hist tenaciousGoalPursuit if group==2,percent fcolor(gs12) lcolor(gs12) bin(30)|| hist tenaciousGoalPursuit if group==1, percent fcolor(none) lcolor(black) bin(30) legend(ring(0) pos(2) cols(1))
    Click image for larger version

Name:	1.png
Views:	1
Size:	55.1 KB
ID:	1491102
    Last edited by Fred Lee; 01 Apr 2019, 00:55.

  • #2
    Can anyone help me? Thanks in advance!

    Comment


    • #3
      Take a look at the -bmargin()- legend suboption. Perhaps something like:
      Code:
      twoway hist tenaciousGoalPursuit if group==2,percent fcolor(gs12) lcolor(gs12) bin(30) /// 
       || hist tenaciousGoalPursuit if group==1, percent fcolor(none) lcolor(black) bin(30)  /// 
       legend(ring(0) pos(2) cols(1) bmargin(t=5 r=5))

      Comment


      • #4
        Originally posted by Scott Merryman View Post
        Take a look at the -bmargin()- legend suboption. Perhaps something like:
        Code:
        twoway hist tenaciousGoalPursuit if group==2,percent fcolor(gs12) lcolor(gs12) bin(30) ///
        || hist tenaciousGoalPursuit if group==1, percent fcolor(none) lcolor(black) bin(30) ///
        legend(ring(0) pos(2) cols(1) bmargin(t=5 r=5))
        Wow, It works! Thanks a lot!

        Comment

        Working...
        X