Announcement

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

  • How to make smaller symbol legend?

    Dear Statalisters,
    I am working on -twoway graph- here is
    Click image for larger version

Name:	red.png
Views:	2
Size:	15.3 KB
ID:	1381185

    How to make smaller symbol legend? I tried using -size, symysize, symxsize - but did not work.
    Any feedback would be greatly appreciated.
    Thank you.

    Best regards,
    Kun Susiloretni



  • #2
    Try within legend option:

    Code:
    twoway (scatter y x) || (scatter z x) , legend(size(vsmall))
    Roman

    Comment


    • #3
      Thanks Roman,
      I have used -size- before. Please see my command below.
      Code:
      twoway (line year se if year==2013, connect() col(gs0)) (line year se if year==2010, connect() col(gs0)) (line year  se if year==2007, connect() col(gs0))  (scatter year  se if quinum==1, msymbol(O)  msize(large) mfcolor(lime) col(gs0)) (scatter year  se if quinum==5, msymbol(O)  msize(large) mfcolor(midgreen) col(gs0)) (scatter year  se if quinum==6, msymbol(O)  msize(large) mfcolor(red) col(gs0)),   by(type, col(1)  scale(1.7) note("") imargin(0 0 0 0)  plotregion( style(none) )  graphregion( fc(white) lc(white) ))  ylab(2007 2010 2013 2016, nogrid angle(horizontal) labsi(vsmall))   xsize(6) ysize(3.2) subtitle(, ring(0) pos(1) nobexpand si(small) lc(white) fc(none)) plotregion(color(white) margin(t=3.5 b=3.5 )) xtitle("Prevalence (%)" , si(small))  ytitle("Year ", si(small)) note("")  xlab(0(5)50,  angle(horizontal) labsi(vsmall)) legend(order(  4 "Q1 Lowest  " 6 "National prevalence" 5 "Q5 Richest")  placement(s) si(vsmall) region(lc(none) fc(none) ls(none)) keygap(*.5) colgap(*.5) pos(4) row(1))
      That's work for text size, but did not work to make smaller symbols.
      Thanks again
      Kun

      Comment


      • #4
        This is a neat use of the by() option to twoway! However your reporting of the code as in #3 makes the code impossible to read. I suspect you need to look at help legend_options. and symxsize() and symysize() options in particular. Minor unrelated observation: can you not replace line year se, connect() with connected year se for brevity's sake?

        Here is your code in more legible format:

        Code:
        twoway  ///
         (line year se if year==2013, connect() col(gs0))    ///
         (line year se if year==2010, connect() col(gs0))    ///
         (line year  se if year==2007, connect() col(gs0))   ///
         (scatter year  se if quinum==1, msymbol(O)         ///
           msize(large) mfcolor(lime) col(gs0))                    ///
         (scatter year  se if quinum==5, msymbol(O)         ///
           msize(large) mfcolor(midgreen) col(gs0))           ///
         (scatter year  se if quinum==6, msymbol(O)         ///
           msize(large) mfcolor(red) col(gs0))                     ///
         , by(type, col(1)  scale(1.7) note("") imargin(0 0 0 0) ///
           plotregion( style(none) )                                      ///
         graphregion( fc(white) lc(white) ))                         ///
         ylab(2007 2010 2013 2016, nogrid angle(horizontal)  ///
         labsi(vsmall))   xsize(6) ysize(3.2)                        ///
         subtitle(, ring(0) pos(1) nobexpand si(small) lc(white) fc(none)) ///
         plotregion(color(white) margin(t=3.5 b=3.5 ))       ///
         xtitle("Prevalence (%)" , si(small))                        ///
         ytitle("Year ", si(small)) note("")                            ///
         xlab(0(5)50,  angle(horizontal) labsi(vsmall))       ///
         legend(order(  4 "Q1 Lowest  " 6 "National prevalence" 5 "Q5 Richest") ///
           placement(s) si(vsmall) region(lc(none)             ///
           fc(none) ls(none)) keygap(*.5) colgap(*.5) pos(4) row(1))

        Comment


        • #5
          Thanks so much Prof. Jenkins ..

          Comment


          • #6
            Dear Prof. Jenkins and all,
            Could you please give suggestion to my graph above?
            Thanks so much
            Best,
            Kun

            Comment


            • #7
              Sorry, I've no time to look again at this right now -- other commitments. You haven't told us what you've tried since message #4 -- I gave you some suggestions to follow up. Whatever, to maximize the chances of others helping you, you need to provide illustrative data so that readers can experiment. Before providing such data, please read the Forum FAQ thoroughly, including the sections about dataex. Also try and strip your code down to the very essential elements only, i.e. to the options associated with the problem you want solved.

              Comment


              • #8
                I agree with Stephen Jenkins's suggestions. In fact judging by #1 I'd say that the symbol legend is already a little too small!

                Comment


                • #9
                  Kun:
                  I have encountered similar issues. Playing around with graph editor, it appears that symbol size in the legend is linked directly to symbol size in the plot itself.

                  Here is an admittedly very clunky workaround (it's not applicable directly to your case, but you'll see the idea). y, x1, and x2 are just some arbitrarily generated variables.

                  Code:
                  twoway (scatter y x1, mcolor(red)) (scatter y x2, mcolor(blue)) (scatter y x1 if _n>_N, mcolor(red) msize(*.5)) (scatter y x2 if _n>_N, mcolor(blue) msize(*.5) legend(order(3 4)))

                  Comment


                  • #10
                    I am sorry Prof. Jenkins. Yes. I did what you suggest but still did not work.
                    Thanks so much Roman, Prof. Jenkins, Nick, and John for all your help.
                    Inspired by John I can fix the graph. Here is

                    Click image for larger version

Name:	q1q5 rev2.png
Views:	1
Size:	32.6 KB
ID:	1382101


                    Best,
                    Kun

                    Comment


                    • #11
                      To close the thread properly, would you please post the code you used to solve the problem? (The FAQ recommends this.) Yours was a tricky problem; posting will help other people too. Thank you.

                      Comment


                      • #12
                        Yes. I just added the same scatter commands with the smaller symbol. Thank you very much.
                        Code:
                        twoway  ///
                         (line year se if year==2013, connect() col(gs0))    ///
                         (line year se if year==2010, connect() col(gs0))    ///
                         (line year  se if year==2007, connect() col(gs0))   ///
                         (scatter year  se if quinum==1, msymbol(O)         ///
                           msize(medlarge) mfcolor(lime) col(gs0))                    ///
                         (scatter year  se if quinum==5, msymbol(O)         ///
                           msize(medlarge) mfcolor(midgreen) col(gs0))           ///
                         (scatter year  se if quinum==6, msymbol(O)         ///
                           msize(medlarge) mfcolor(red) col(gs0))                     ///
                         (scatter year  se if quinum==6, msymbol(O)         ///
                           msize(large) mfcolor(red) col(gs0))                     ///
                         (scatter year  se if quinum==1, msymbol(O)         ///
                           msize(large) mfcolor(lime) col(gs0))                    ///
                         (scatter year  se if quinum==5, msymbol(O)         ///
                           msize(large) mfcolor(midgreen) col(gs0))           ///
                         , by(type, col(1)  scale(1.7) note("") imargin(0 0 0 0) ///
                           plotregion( style(none) )                                      ///
                         graphregion( fc(white) lc(white) ))                         ///
                         ylab(2007 2010 2013 2016, nogrid angle(horizontal)  ///
                         labsi(vsmall))   xsize(6) ysize(3.2)                        ///
                         subtitle(, ring(0) pos(1) nobexpand si(small) lc(white) fc(none)) ///
                         plotregion(color(white) margin(t=3.5 b=3.5 ))       ///
                         xtitle("Prevalence (%)" , si(small))                        ///
                         ytitle("Year ", si(small)) note("")                            ///
                         xlab(0(5)50,  angle(horizontal) labsi(vsmall))       ///
                         legend(order(  4 "Q1 Lowest  " 6 "National prevalence" 5 "Q5 Richest") ///
                           placement(s) si(vsmall) region(lc(none)             ///
                           fc(none) ls(none)) keygap(*.5) colgap(*.5) pos(4) row(1))
                        Last edited by Kun Susiloretni; 05 Apr 2017, 00:29.

                        Comment


                        • #13
                          Your solution probably served your purpose but did not solve the problem. What if you wanted to have larger markers in the plots but smaller leggends or vice versa? In your solution, the legend size is being defined from the `msize' option. As Stephen pointed out in #4, it is purely a 'by' option problem. If you could create your plots without the 'by' option, I assume you could have controlled the size of the markers independently with ('msize) and legend size with 'symxsize', 'symysize'.
                          Roman

                          Comment


                          • #14
                            Small but for some people serious point: red and green are difficult for many to tell apart.

                            Comment


                            • #15
                              So sorry, I have difficulties in English. I couldn't address comments properly

                              #13. Yes, agree Roman. I did not solve the problem . I use the by() to show subtitle in the right part of graph. I give example datasets below.

                              Code:
                              * Example generated by -dataex-. To install: ssc install dataex
                              clear
                              input int year float se byte(quinum type)
                              2007 38.9 2 1
                              2007 37.2 3 1
                              2007 34.1 4 1
                              2007 30.3 5 1
                              2007 36.8 6 1
                              2016    . 1 2
                              2016    . 2 2
                              2016    . 3 2
                              2016    . 4 2
                              2016    . 5 2
                              2016  6.9 6 2
                              2013 13.4 1 2
                              end
                              label values type type
                              label def type 1 "Stunting, under five children", modify
                              label def type 2 "Low birthweight", modify
                              #14. Sorry Nick. Again, I don't understand what you mean. Could you please say in a simple way?

                              Any suggestions to solve the problem will be very grateful.
                              Best
                              Kun

                              Comment

                              Working...
                              X