Announcement

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

  • Suppress legends

    How do i remove the legends for the scatterplot in this code?

    twoway (scatter HGB Total_CO2 if SEX==0, mcolor(red%05)) (scatter HGB Total_CO2 if SEX==1, mcolor(blue%05)) || (lfit HGB Total_CO2 if SEX==0, lcolor(red) lpattern(dash))|| (lfit HGB Total_CO2 if SEX==1, lcolor(blue) lpattern(dash)) || (lfit HGB Total_CO2, lcolor(black) lwidth(medthick)), ytitle(HGB) xtitle("Dietary GHGE (kg/day)") legend(label (3 "All") label (4 "Women") label (5 "Men"))

    Click image for larger version

Name:	Stata.png
Views:	1
Size:	317.8 KB
ID:	1723964


  • #2
    Use the -order()- option within -legend()- to control the order and appearance of which legend elements are displayed. Note: Code is untested.

    Code:
    twoway (scatter HGB Total_CO2 if SEX==0, mcolor(red%05)) || ///
        (scatter HGB Total_CO2 if SEX==1, mcolor(blue%05)) || ///
        (lfit HGB Total_CO2 if SEX==0, lcolor(red) lpattern(dash)) || ///
        (lfit HGB Total_CO2 if SEX==1, lcolor(blue) lpattern(dash)) || ///
        (lfit HGB Total_CO2, lcolor(black) lwidth(medthick)) ///
        , ytitle(HGB) xtitle("Dietary GHGE (kg/day)") legend(order(3 4 5) label (3 "All") label (4 "Women") label (5 "Men"))
    Last edited by Leonardo Guizzetti; 16 Aug 2023, 08:36.

    Comment


    • #3
      -leg(off)- in #2 turns off the legend. Use -order()-

      Code:
      legend(order(3 "All" 4 "Women" 5 "Men"))
      This excludes the non-specified items.

      Comment


      • #4
        Originally posted by Andrew Musau View Post
        -leg(off)- in #2 turns off the legend. Use -order()-

        Code:
        legend(order(3 "All" 4 "Women" 5 "Men"))
        This excludes the non-specified items.
        Indeed, I misread the question and answered the title. My post has been edited.

        Comment

        Working...
        X