Announcement

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

  • Need help with combining plots and figures

    I need help with the following issues:

    1. Combining Plots
    I have the following syntax for my plots:
    Code:
    twoway (scatter AB_Y Day if Sampletype ==0 & Run==0), play (Template_Background) ylabel(0(0.01)0.03, angle(0) grid) yline(0.02)
    twoway (scatter CD_Y Day if Sampletype ==0 & Run==0), play (Template_Background) ylabel(0(0.1)0.2, angle(0) grid) yline(0.1)
    twoway (scatter EF_Y Day if Sampletype ==0 & Run==0), play (Template_Background) ylabel(0(5)15, angle(0) grid) yline(10)
    twoway (scatter GH_Y Day if Sampletype ==0 & Run==0), play (Template_Background) ylabel(0(0.1)0.3, angle(0) grid) yline(0.2)
    After some search, I could combine them according to the following syntax:
    Code:
    combineplot Day (AB_Y CD_Y EF_Y GH_Y) if Sampletype ==0 & Run==0: scatter @x @y
    Yet, the code above is not optimal as I need to include my Template, the ylabel specs, and the reference line for the individual plots. Is there a way to combine the plots in my first code using one (or short) syntax?

    And how to label the x-axis with only "Day" because right now I get "Day" together with the name of the group (example "Day analyzer Y")?

    2. Combining Figures/Images
    I have the following loop for my scatter plots (A to Q are analytes in blood samples analyzed in analyzer X and analyzer Y):
    Code:
    putdocx begin
    putdocx paragraph
    #delimit ;
    putdocx text ("Scatter plots of the A-Q analyzed in the X and Y analyzers.");
    #delimit cr
    
    foreach stub in A_ B_ C_ D_ E_ F_ G_ H_ I_ J_ K_ L_ M_ N_ O_ P_ Q_ {
        aaplot `stub'X `stub'Y, play (Template_aaplot)
        graph export `stub'1.png
        putdocx image `stub'1.png
    }
    
    putdocx save Results_XX, replace
    However, the size of the obtained plots/images are too large and every plot (saved as PNG format) takes almost the whole Word page. How can I combine the obtained images to fit in one to two pages?

  • #2
    Code:
     help gr combine

    Comment


    • #3
      Thank you Andew! I made some progress after reading in the graph combine document. When I run the following code, I cannot putdocx the combined image. Am I doing something wrong? Or maybe I just need to adjust the size of the image? I tried using "width" but it didn't work.
      Code:
      putdocx begin
      putdocx paragraph
      #delimit ;
      putdocx text ("Scatter plots of the Background analyzed in the BM800 Medonic analyzer.");
      #delimit cr
      
      twoway (scatter AB_Y Day if Sampletype ==0 & Run==0), play (Template_Background) ylabel(0(0.01)0.03, angle(0) grid) yline(0.02)  xtitle(Day) saving(AB) 
      twoway (scatter CD_Y Day if Sampletype ==0 & Run==0), play (Template_Background) ylabel(0(0.1)0.2, angle(0) grid) yline(0.1) xtitle(Day) saving(CD) 
      twoway (scatter EF_Y Day if Sampletype ==0 & Run==0), play (Template_Background) ylabel(0(5)15, angle(0) grid) yline(10)  xtitle(Day) saving(EF)
      twoway (scatter GH_Y Day if Sampletype ==0 & Run==0), play (Template_Background) ylabel(0(0.1)0.3, angle(0) grid) yline(0.2) xtitle(Day) saving(GH)
      
      graph combine AB.gph CD.gph EF.gph GH.gph
      graph save Background.png 
      putdocx image Background.png
      failed to add image
      r(198);
      Is it possible to have a simpler code for my first code even if the axes and the reference lines are different for the different variables?

      Comment


      • #4
        The error arises from your penultimate line

        graph save Background.png
        You should export the graph as PNG. If you know the directory where your graphs are stored

        Code:
        graph combine AB.gph CD.gph EF.gph GH.gph
        graph export "C:\MY_DIRECTORY\Background.png", as(png)
        putdocx image Background.png
        Otherwise, right click on the combined graph and choose "save as png".

        Comment


        • #5
          Thank you Andrew! I get what I want now.

          Comment

          Working...
          X