Announcement

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

  • Marker symbols and line patterns not showing in legend (combomarginsplot)

    Greetings,

    I'm running Stata 15.1 on OSX. I'm trying (struggling) to graph the predicted margins from 6 different bivariate regressions models using combomarginsplot. When I adjust the line patterns and symbols of the respective plots, however, they do not appear in the corresponding legend. To illustrate, this is what I mean:
    Click image for larger version

Name:	legend prob.jpeg
Views:	2
Size:	622.5 KB
ID:	1486778

    Does anyone know how to fix this? Thanks in advance!
    Attached Files

  • #2
    Forgot to include my code. Here it is:
    Code:
    combomarginsplot blackcon blacklib hispcon hisplib whitecon whitelib, legend(order(1 "Black Conservative" 2 "Black Liberal" 3 "Hispanic Conservative" 4 "Hispanic Liberal" 5 "White Conservative" 6 "White Liberal")) xsize(8) plot1opts(lpattern(shortdash_dot) msymbol(X) mcolor(gray) lcolor(gray)) ci1opts(lcolor(gray)) plot3opts(lpattern(dash) msymbol(diamond_hollow) lcolor(gs2) mcolor(gs2)) ci3opts(lcolor(gs2) msymbol(diamond_hollow)) plot5opts(lpattern(vshortdash) msymbol(circle) mcolor(gs8) lcolor(gs8)) ci5opts(lcolor(gs8)) plot2opts(lpattern(dash_dot_dot) msymbol(+) mcolor(gray) lcolor(gray)) ci2opts(lcolor(gray)) plot4opts(lpattern(shortdash_dot) msymbol(smcircle) mcolor(gs13) lcolor(gs13)) ci4opts(lcolor(gs13)) plot6opts(lpattern(solid) msymbol(diamond) mcolor(gs5) lcolor(gs5)) ci6opts(lcolor(gs5))

    Comment


    • #3
      Combomarginsplot is (my) user-written program.

      The problem is with your legend option: you are asking for the legend to include information on the first six plots, which are the confidence interval plots, not the estimates (i.e., the lines). This is because marginsplot, which underlies combomarginsplot, plots the CIs first, then the the estimates, which means the estimates are plotted on top of the CIs rather than under them.

      You should use the labels() option of combomarginsplot, which is designed for just this purpose:

      Code:
      combomarginsplot blackcon blacklib hispcon hisplib whitecon whitelib,   ///
           labels("Black Conservative" "Black Liberal" "Hispanic Conservative"  ///
                  "Hispanic Liberal" "White Conservative" "White Liberal") ///
           ...
      (Note that you could also get what you want with a legend order() option that runs from 7 through 12:

      Code:
      combomarginsplot blackcon blacklib hispcon hisplib whitecon whitelib, ///
           legend(order(7 "Black Conservative" 8 "Black Liberal" 9 "Hispanic Conservative" ///
                        10 "Hispanic Liberal" 11 "White Conservative" 12 "White Liberal")) ///
           ...

      Comment


      • #4
        Thanks Nicholas! That was very helpful.

        Comment


        • #5
          One more tangential follow-up: if you have Stata 15 (and therefore transparency), I'm a big fan of making the CI's into shaded areas with transparency (with marginsplot, or with combomarginsplot):

          Code:
          marginsplot  , recastci(rarea) ciopts(color(%20)) ...
          or

          Code:
          combomarginsplot ... , recastci(rarea) ciopts(color(%20)) ...

          Comment


          • #6
            Dear both, thank you for the insightful discussion on this!
            I am having a similar trouble. I would like to adjust my legend to the graph attached so that it shows that different line types correspond to different values. I have tried your approach with labels, but did not get successful results. Any chance you know how I can fix this? Thank you very much in advance!

            Here is the code I used:
            Code:
             marginsplot, recast(line) recastci(rcap) scale(0.85) title("") ytitle("Contributor's effort (natural log)", height(5)) plot1opts(lpattern(solid) lcolor(gs0) msymbol(smcircle) mcolor(gs0) msize(tiny)) ci1opts(lcolor(gs8)) plot2opts(lpattern(dash) lcolor(gs0) msymbol(smcircle) mcolor(gs0) msize(tiny)) ci2opts(lcolor(gs8)) plot3opts(lpattern(dot) lcolor(gs0) msymbol(smcircle) mcolor(gs0) msize(tiny)) ci3opts(lcolor(gs8)) plot4opts(lpattern(dash_dot) lcolor(gs0) msymbol(smcircle) mcolor(gs0) msize(tiny)) ci4opts(lcolor(gs8)) plot5opts(lpattern("--.--") lcolor(gs0) msymbol(smcircle) mcolor(gs0) msize(tiny)) ci5opts(lcolor(gs8)) legend(cols(3) order(1 "Min=0" 2 "Median=.07" 3 "Mean=0.12" 4 "90th %-le=0.34" 5 "Max=0.87")) legend(subtitle("Values of ln(Skill match+1) (/10):", position(11)) position(7))
            Attached Files

            Comment


            • #7
              #6 this is not about combomarginsplot. But the issue is the same as I reference in #3: you are telling Stata you want the various CI bars as the legend. You need something like this:

              Code:
              marginsplot, ... legend(order(6 "Min=0" 7 "Median=.07" 8 "Mean=0.12" 9 "90th %-le=0.34" 10 "Max=0.87")) ...

              Comment

              Working...
              X