Announcement

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

  • Legend rearrangement after marginsplot with by option

    Hi all,

    I may be approaching with a very simple problem but I can't figure out the cause. Here is the demonstration of the problem using the 'auto' dataset:


    Code:
    sysuse auto, clear
    
    margins foreign, at(headroom=(2 3 5) rep78=(2 3 5))
    
    marginsplot, by(foreign)
    The marginsplot above comes with legends at 3'o clock position with one column or 3 rows (rep78 = 2, 3, 5). Say I want the legends at 6'o clock postion with 3 columns or one row; so the codes I used:


    Code:
    marginsplot, by(foreign) byopts(legend(pos(6) col(3)))
    This does bring the legend position at 6'0 clock position but the legends still remain in one column. Any idea why is this? Why the position option is respected but the row/column option is ignored? I tried in vein bringing the legend option as:

    Code:
    marginsplot, by(foreign, legend(pos(6) col(3)))
    But it says option legend() not allowed . Any idea?

    StataNow version: version 18.5
    OS: Mac

    Thanks.
    Roman

    Roman

  • #2
    It's a bit counter-intuitive, but you need a separate -legend()- option outside -byopts()- to specify the number of columns in the legend.

    Code:
    sysuse auto, clear
    regress mpg turn i.foreign head rep78
    margins foreign, at(headroom=(2 3 5) rep78=(2 3 5))
    marginsplot, by(foreign) byopts(legend(pos(6))) leg(col(3))
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	44.4 KB
ID:	1761702

    Comment


    • #3
      Thanks so much Andrew. You have always been fantastic. Stata is so confusing sometimes.
      Roman

      Comment

      Working...
      X