Announcement

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

  • how to combine two graphs into one?

    Hello, I would like to combine the below two graphs into one. The first one shows observed data, and the second one shows predicted probabilities from a model. Below is the code and the two graphs. Is this possible, if so, how should the code be adjusted? thanks!


    Code:
    ****Graph 1
    graph twoway (scatter prop year if gender_n==4, msymbol(Oh)) (scatter prop year if gender_n==5, msymbol(S)) (scatter prop year if gender_n==6, msymbol(S)), legend(label(5 M) label(4 F) label(6 U))
    
    ****Graph 2
    
    quietly mlogit gender_n year, rrr vce(cluster person)
    
    quietly margins, at(year = (2007(1)2013)) post
    
    marginsplot, recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea) title("Marketing") xtitle("year") ytitle("Predicted Probability") xlabel(2007 "2007" 2008 "2008" 2009 "2009" 2010 "2010" 2011 "2011" 2012 "2012" 2013 "2013") plotd(,label( "F" "M" "U"))
    Graph 1:
    Click image for larger version

Name:	madeup.png
Views:	1
Size:	49.8 KB
ID:	1632493




    Graph 2:

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	85.8 KB
ID:	1632494




    Last edited by MJ Smith; 19 Oct 2021, 18:08.

  • #2
    help graph combine

    Comment


    • #3
      My guess is different, that you want to put stuff in just one graph. The addplot() option of marginsplot lets you plot other variables in the same space.

      I'd move your legend to pos(3) as it's on top of some of the curves. You can gain a little space by zapping the xtitle(). The reader who needs to be told that 2007 to 2013 means yearly dates is in the wrong ball game.

      Comment


      • #4
        Thanks Nick - addplot() worked nicely. Also, thanks for the additional tips - you're probably right that the reader would know the x axis is the year

        Comment


        • #5
          Good, but note George Ford's helpful tip, which is often the answer too.
          Last edited by Nick Cox; 19 Oct 2021, 18:59.

          Comment


          • #6
            Good to know about graph combine. Thanks George!

            Comment


            • #7
              Dear Statisticians,
              I want to merge two graphs (Bland-Altman plot) into one. While making the graphs, I saved them to my desktop with a particular graph name. When I put the merge command, it displayed no graph in memory with that name. Kindly advise how I can save my graph automatically to the memory.

              Comment


              • #8
                Code:
                help graph save

                Comment

                Working...
                X