Announcement

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

  • Changing the overall size of marginsplots

    Dear Statalisters,

    i am using the marginsplot-command with "by" options to display predicted margins for three different groups. I want those three separate graphs aligned in one single row and accordingly speficy this within the "by_options". The problem is that the resulting combined graph looks stretched, since without more than one column, there is more vertical space to fill. You can see this in the attached picture.

    Click image for larger version

Name:	Screenshot 2022-04-01 122404.jpg
Views:	1
Size:	52.8 KB
ID:	1657348


    Is there a way to adjust the vertical size of those bars to make the overall plot look more dense? Mind you, i do not want to change the axis scales. Looking into relevant helpfiles, I have not found such an option and since the "size-"option that comes with other graphics does not work for marginsplots, i am at my wit's end.

    Thank you

    Dominik

  • #2
    Provide a reproducible example using dataex (see FAQ Advice #12) and elaborate more on how one can increase the height of the bars without affecting the axis scale.

    Comment


    • #3
      Sorry, but data privacy rulings do not allow me to share detailed examples out of the dataset i'm using. But i was wrong in stating that i don't intend to change the axis scales. What i want to keep is actually just the axis range for the bars, which should also remain the same for all three of them.
      My code looks like this:

      marginsplot, by(groupvar) recast(bar) byopts(title("Die Regierung sollte Einkommen angleichen') rows(1)) xtitle("") ytitle("Ausmaß an Zustimmung") scheme(sj) xlabel(1 "Privilegierte" 2 "Benachteiligte" , labsize(small))

      Without adding the option to arrange the graphs in one single row, Stata would by default produce this marginsplot:

      Click image for larger version

Name:	Screenshot 2022-04-01 152402.jpg
Views:	1
Size:	49.3 KB
ID:	1657375


      As we see, the overall height of the whole picture remains the same, but since the graphs are aligned below each other, the single frames are only half as long, making the axes/bars appear more dense. Essentially, i would like to keep those (vertical size-wise) smaller frames for each group while arranging them in one single horizontal row. This way, i'd get a plot that is more wide than long.

      I hope you understand. Thanks for your help.

      Comment


      • #4
        The FAQ linked in #2 addresses the issue of confidential data. Look at

        Code:
        help aspect_option
        Here is a reproducible example of your problem, specifying an aspect ratio of 0.8.

        Code:
        webuse nhanes2, clear
        set seed 01042022
        gen byvar= runiformint(1,3)
        regress bpsystol sex##byvar##c.bmi
        margins sex, over(byvar)
        marginsplot,   by(byvar) recast(bar) aspect(0.8) ///
        byopts(title("Die Regierung sollte Einkommen angleichen") ///
        rows(1)) xtitle("") ytitle("Ausmaß an Zustimmung") scheme(sj) ///
        xlabel(1 "Privilegierte" 2 "Benachteiligte" , labsize(small))
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	58.7 KB
ID:	1657383

        Comment


        • #5
          Thank you, Andrew. This solves my problem and i wonder how i missed this quite simple solution. I guess i was too focused on specific options for marginsplots rather then plot-options in general. Also, thanks for your remark regarding the provision of reproducable data examples.

          Comment

          Working...
          X