Announcement

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

  • Suppress surrounding line of a legend

    Hello statalisters,

    I've been struggling with this for a moment already and don't know what to do...

    I've generated this kdenisty plot and I want to have no line around the legend. I thought that by using : legend( region(lwidth(none) margin(none)) the problem would be gone, but it won't.

    Here is my code (and my figure) :

    twoway kdensity wucaf_u24_mg if sex==1 & index==1, lwidth(*2.5) || kdensity wucaf_u24_mg if sex==2 & index==1, name(ucaf_sex) ///
    legend(ring(0) pos(2) textfirst cols(1) region(lwidth(none) margin(none)) order(1 "Males" 2 "Females")) lwidth(*2.5) subtitle("By sex")

  • #2
    The figure
    Attached Files

    Comment


    • #3
      Try the following instead:
      Code:
       legend( region(lstyle(none)) )
      And if you want a full black/weight lean scheme, also add
      Code:
      graphregion(color(white))  scheme(s2mono)

      Please note the use of CODE delimiters to display code and output. This makes material much easier to read by comparison with yours, I submit. See the FAQ on how to use CODE delimiters

      Comment


      • #4

        Code:
        legend(...region(lpattern(blank))...)

        Comment


        • #5
          Great, thanks a lot

          Comment


          • #6
            BTW I bought your book Svend, it's great

            Comment


            • #7
              I'm sorry guys, but your propositions don't really work :

              neither :
              Code:
              legend( region(lstyle(none)) )
              nor :

              Code:
               legend(...region(lpattern(blank))...)

              Comment


              • #8
                "don't really work " is a very unhelpful description for anyone who considers assisting you! (See the FAQ on this.) Show us exactly what you typed into Stata (the whole graphics command) and exactly what you got back -- as the FAQ advises.

                Comment


                • #9
                  Well, none of the codes that Svend nor you proposed do result in suppressing the lines around the legend... Neither the use of both of them...

                  Code:
                  twoway kdensity wucaf_u24_mg if sex==1 & index==1, lwidth(*2.5) || kdensity wucaf_u24_mg if sex==2 & index==1, name(ucaf_sex) ///
                   legend(ring(0) pos(3) textfirst cols(1) region(lpattern(blank) lwidth(none) lstyle(none)) order(1 "Males" 2 "Females")) lwidth(*2.5) subtitle("By sex")
                  Thank you for your kind help
                  Attached Files

                  Comment


                  • #10
                    You mean, it did not solve the problem? On your graph, which was created using the s2color scheme, I can see a faint line around the legend area. I could even reconstruct it:
                    Code:
                    set scheme s2color
                    sysuse auto, clear
                    twoway (scatter mpg weight if foreign==0)(scatter mpg weight if foreign==1) ///
                    , legend(region(lpattern(blank)) ring(0) pos(2))
                    This happens with the s2 schemes, not with the s1 schemes. Removing region(lpattern(blank)) leads to a distinct line around the legend.

                    Is it the faint line around the legend that you dislike. In that case, I don't know any other remedy than swithching sceme to, e.g., s1color, lean1, or lean2.

                    Comment


                    • #11
                      How about this?

                      Code:
                      set scheme s2color
                      sysuse auto, clear
                      twoway (scatter mpg weight if foreign==0)(scatter mpg weight if foreign==1) ///
                      , legend(region(color(none)) ring(0) pos(2))

                      Comment


                      • #12
                        Phil's suggestion may create what Dusan wants. However, the background in the legend box is transparent, making the gridline visible behind the text. Perhaps this is a better solution:
                        Code:
                        legend(region(color(white))...)

                        Comment


                        • #13
                          Hello,

                          At last! Thank you all!

                          Comment

                          Working...
                          X