Announcement

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

  • Add marker to legend in marginsplot

    I'm trying to customize my plots, and I would like to include the marker for each group in the legend, however, I've been unable to do so.

    The default plot retains the symbol in the legend; I would like to do the same.



    Code:
    use http://www.stata-press.com/data/r13/systolic.dta, clear
    
    
    anova systolic i.drug i.disease i.drug#i.disease
    
    estat esize
    
    margins i.drug#i.disease , at( (asbalanced) _factor)
    
    
    
    marginsplot , name(margins_default, replace) title(" ") ///
    
    
    
    marginsplot , name(margins_custom, replace) title(" ") ///
    legend(order( 1 "ds1"  2 "ds2" 3 "ds3" ) position(6) ring(75) )  ///
    plot1opts(    msymbol(Oh) mcolor("0 75 135") mlwidth(*.85)  lcolor("0 75 135") lwidth(*.85)       ) ///
    ci1opts(lcolor("0 75 135") lwidth(*.85) ) ///
    plot2opts(msymbol(O) mcolor("150 150 150") mlwidth(*.85)  lcolor("150 150 150") lwidth(*.85)      ) ///
    plot3opts(msymbol(X) mcolor("200 200 200") mlwidth(*.85)  lcolor("200 200 200") lwidth(*.85)      ) ///
    ytitle("Model Based Mean", margin(0 3 0 0))  ///
    xtitle("Drugs Used", margin(3 0 3 3) ) xlabel(1 "A" 2 "B" 3 "C"  4 "D")  
    graph display margins_test , ysize(5) xsize(7)  margins(l=10 r=20 b=5)










  • #2
    Jonathan,
    Please see FAQ #8 about cross-posting.


    The plots you are referencing in your legend (1, 2, 3) are the ci plots which are rcap lines without symbols. To have the legend reflect the markers, you need to specify plots 4, 5, & 6:


    Code:
    clear
    use http://www.stata-press.com/data/r13/systolic.dta, clear
    
    
    anova systolic i.drug i.disease i.drug#i.disease
    
    estat esize
    
    margins i.drug#i.disease , at( (asbalanced) _factor)
    
    
    
    marginsplot , name(margins_default, replace) title(" ") ///
    
    
    marginsplot , name(margins_custom, replace) title(" ")   ///
    legend(order( 4 "ds1"  5 "ds2" 6 "ds3" ) position(6) ring(75) )  ///
    plot1opts(msymbol(Oh) mcolor("0 75 135") mlwidth(*.85)  lcolor("0 75 135") lwidth(*.85)       ) ///
    ci1opts(lcolor("0 75 135") lwidth(*.85) ) ///
    plot2opts(msymbol(O) mcolor("150 150 150") mlwidth(*.85)  lcolor("150 150 150") lwidth(*.85)      ) ///
    plot3opts(msymbol(X) mcolor("200 200 200") mlwidth(*.85)  lcolor("200 200 200") lwidth(*.85)      ) ///
    ytitle("Model Based Mean", margin(0 3 0 0))  ///
    xtitle("Drugs Used", margin(3 0 3 3) ) xlabel(1 "A" 2 "B" 3 "C"  4 "D")  
    
    graph display margins_custom , ysize(5) xsize(7)  margins(l=10 r=20 b=5)
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      As Carole hinted, this was cross-posted at http://stackoverflow.com/questions/2...insplot-legend

      Comment

      Working...
      X