Announcement

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

  • Graph Combine

    I would like to combine about 200 graphs in one pdf so that each graph is displayed below each other in one column and the original aspect ratio is kept. However if I use the code below I get a combined pdf where each graph is very long horizontally and very small vertically.


    Code:
    local graphs ""
    foreach var of varlist _all {
    line `var' year, name(`var') title(`var') graphregion(color(white)) xlabel(1980(2)2010,labsize(small)) ytitle("")
    local graphs "`graphs' `var'"
    }
    gr combine `graphs', col(1) ysize(20) graphregion(color(white))
    gr export check.pdf, replace

  • #2
    I'd be interested to see if anybody has a Stata solution to this problem. I don't see a way to do it. I would be more likely to just save each graph individually as a PDF and then combine them in Acrobat.

    Comment


    • #3
      Combining the pdfs in a pdf editor would be one way. I did it several times. However it would be more convenient to do it in stata! Let's see if someone has a solution!

      Comment


      • #4
        You can think of gr combine as merging graphs into one page. 200 graphs in one column (in one page) is not reasonable, so you will want to do several gr combines. If you specify the option -aspectratio(1)- in the graphs to be combined, gr combine respects this.

        Code:
        sysuse auto, clear
        forval i=1/3{
               scatter mpg rep78, saving(gr`i', replace) aspectratio(1)
        }
        gr combine gr1.gph gr2.gph gr3.gph, col(1) scheme(s1color)
        Res.:

        Click image for larger version

Name:	Graph.png
Views:	1
Size:	64.3 KB
ID:	1541869

        Comment


        • #5
          With ysize(20) inches would mean that 200 graphs in one column, each individual graph would .1 of inch in height. However, since the minimum size is 1 inch would not be able to maintain the original aspect ratio of ysize(4) xsize(5.5).

          If you fixed the height of the page at 20 inches then you could put 5 graphs with 4/5.5 aspect ratio. The maximum size is 100 inches, so you could put 25 graphs on one pdf page with the original aspect raito.

          Comment


          • #6
            The solution with fixing the aspect ratio does not work. Probably because of the reason Scott has mentioned. Scott Merryman is there a way to create one pdf with several pages with 25 graphs on each page with graph combine?

            Comment


            • #7
              Code:
              sysuse auto,clear
              forv page = 1/4 {
                  forv i = 1/25 {
                      scatter mpg price , name(gr_`page'_`i', replace)
                      local graphs "`graphs' gr_`page'_`i'"
                  }
                  gr combine `graphs', col(1) ysize(100) name(gr_`page', replace)
                  graph export "gr_`page'.pdf", as(pdf) name("gr_`page'") replace
              local graphs ""
              }
              graph drop _all
              This will create 4 pages of 25 graphs where each page is 100 inches in length.

              However, if you just want the graphs to be in a pdf document you can use -putpdf- Page size is limited to letter, legal, A3, A4, A5, B4, or B5.

              Code:
              putpdf clear
              sysuse auto,clear
              putpdf begin, pagesize(letter) margin(all,.25) halign(center)
              putpdf paragraph
              forv i = 1/25 {
                  scatter mpg price, name(gr_`i', replace)
                  graph export gr_`i'.png, as(png)  replace
                  putpdf image gr_`i'.png, height(4) width(6)
              }
              putpdf save myreport.pdf , replace

              Comment

              Working...
              X