Announcement

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

  • Graph combine many graphs

    Hello,

    I have created a large number of graphs (~200), that I want to combine so as to have long panel of 3 columns. The point is to be able to glance at these and compare to identify problematic series.

    When I use the standard graph combine, function, specifying the number of columns and rows, it fits everything into a small space and the graphs are unreadable.

    I'm not sure if the option exists, but is it possible to maintain a readable size and just have a long downwards panel? I've done some searching but can't seem to find something on this.

    Thank you very much!

  • #2
    Clara,

    How about using the graph display command with the xsize() option. Does the following work for your purposes?

    Code:
    sysuse auto, clear
    gr tw (scatter mpg weight if foreign==0, name(g1, replace) nodraw)
    gr tw (scatter mpg weight if foreign==1, name(g2, replace) nodraw)
    graph combine g1 g2, ycommon name(combined, replace)
    graph display combined, xsize(10)
    Best,
    Alan

    Comment


    • #3
      You want to combine all 200 graphs in one graph with three columns of individual graphs that all remain legible. That is possible if you create a large image that you can then review in an image viewer. The iscale() option of graph combine is useful for this purpose.

      The example below probably won't run with a 32-bit operating system because you cannot create a PNG file with the maximum theoretical height of 16,000 pixels due to memory limitations. The graph combine takes a minute or two with that many graphs.

      Code:
      sysuse auto
      local graphs ""
      forval i = 1/200 {
        scatter mpg weight, name(g`i', replace) nodraw
        local graphs "`graphs' g`i'"
      }
      graph combine `graphs', col(3) xsize(1.5) ysize(20) iscale(*2)
      graph export graphs.png, height(16000)

      Comment


      • #4
        Here is the large graph created with the code above. It is a combination of 200 individual graphs, exported as a PNG with a height of 16000 pixels.
        Click image for larger version

Name:	graphs.png
Views:	1
Size:	1.01 MB
ID:	1294150

        Comment


        • #5
          Thank you very much Alan and Friedrich! I have been implementing the option Friedrich proposed, and there seems to be an issue with the way I'm defining the local macro. In putting the the same code as you specificed, I'm getting this error message:

          graph combine `graphs', col(3) xsize(1.5) ysize(20) iscale(*2)

          incompatible types

          may not assign class to double

          Do you know if there is a quick way to fix this?

          Again, thank you very much.

          Comment


          • #6
            Please show us the code upstream of that.

            Comment


            • #7
              Yes sure, here it is.
              ---
              local graphs ""

              local countrylist 111 112 122 124 128 132 134 135 136 137 138 142 144 146 156 158 163 172 174 176 178 181 182 184 186 193 196 199 213 218 223 228 233 ///
              238 243 248 253 258 263 268 273 278 283 288 293 298 299 309 311 312 313 316 321 328 336 339 343 351 353 361 362 364 366 369 419 423 429 433 436 439 443 446 ///
              449 453 456 459 463 466 469 474 512 513 514 516 518 522 524 528 532 534 536 537 542 544 548 556 558 564 565 566 576 578 582 611 612 614 616 618 ///
              622 624 626 628 632 634 636 638 642 643 644 646 648 652 654 656 662 664 666 668 672 674 676 678 682 684 686 688 692 694 698 714 716 718 722 724 ///
              726 728 732 733 734 738 742 744 746 748 754 813 819 826 846 853 862 866 867 868 869 911 912 913 914 915 916 917 918 921 922 923 924 925 926 927 ///
              934 935 936 939 941 942 943 944 946 948 960 961 962 963 964 965 967 968

              foreach country of local countrylist {

              line TT Year if _Country_code=="`country'" & dum==1 & Year>= 1994 ///
              || line TT_1995 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT_1996 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT_1997 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT_1998 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT_1999 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT_2000 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT_2001 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT_2002 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT_2003 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT_2004 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT_2005 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT_2006 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT_2007 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT_2008 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT_2008 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT_2009 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT_2010 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT_2011 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT_2012 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT_2013 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT_2014 Year if _Country_code=="`country'" & Year>= 1994, lpattern(dash) ///
              || line TT Year if _Country_code=="`country'" & Pub_year==2014 & Year>= 1994 ///

              ||, ///
              title(`...') subtitle("...") ///

              legend( on order(1 23) label(1 "...") label(23 "....")rowgap(minuscule) keygap(minuscule) symysize(small) symxsize(small) colgap(minuscule) cols(11) size(tiny)

              forcesize) ///

              ylabel(,grid) xlabel(,grid)

              local graphs "`graphs' g`country'"

              }

              graph combine `graphs', col(3) xsize(1.5) ysize(20) iscale(*2)

              graph export graphs.png, height(16000)
              ---

              Comment


              • #8
                As far as I can see you never apply name() to each graph. The effect is to draw graphs and then discard them without saving.

                Comment


                • #9
                  There is this example of the code for graph combine in the post #3 that helps combine a large number of graphs: graph combine `graphs', col(3) xsize(1.5) ysize(20) iscale(*2)
                  however, this code does not produce a nice combined graph for any set of graphs; I am wondering if there is a way to specify options in order to combine any set of graphs and keep their all original properties? One could do this easily by exporting each graph into a high quality .png and combine them all 'manually' in any graphics software like photoshop - however, for me this would not be the ideal strategy; Could I easily achieve this in Stata, using graph combine?

                  Comment


                  • #10
                    graph combine has two options for specifying the graphs. One uses named graphs which are created by passing an argument to the name parameter of the graph command. The other is to save the graph to disk and pass the name of the .gph file that was created. With the first option you need to make sure your system has sufficient memory to keep all the graphs in memory simultaneously. With the second option you need to be patient enough to cope with the lag of the additional time required to process the I/O operations. If the user knows how large of a combined graph they would like to create and the size they would like the individual graphs to be, they could use brewtheme/brewscheme to create a scheme file that would set the sizes in the scheme file. I'll check to make sure there are options available for setting the sizes (it currently defaults to a 9 X 6.5" graph to fill a US Standard Letter page with 1 inch margins) and can push those options into the development branch of the repository tomorrow morning if they aren't available. To see an example of how you would set the global attributes for graphs check out the program's website at https://wbuchanan.github.io/brewscheme/brewtheme. There are also some additional features that I've been working on that are shown there as well.

                    Comment


                    • #11
                      Thank you very much for this prompt and helpful reply. I am using the second option which indeed requires a bit of patience. To be honest, I have a quite vague a priori idea how large of a combined graph I would like to have: I would like the size of the combined graph just to follow exactly the sizes of my basic graphs, and I know that I want to have 3 columns and would like the subgraphs to have reasonable distances one from another (they are all of equal sizes as in the post #4). So if such a simplified default/automatized solution with a minimum number of option parameters could emerge due to the work of the development branch, this would be absolutely great. Thank you very much,

                      Comment


                      • #12
                        Jan Sadowski using brewtheme, you'd want something like:

                        Code:
                        brewtheme smpanels, graphsize("x 3" "y 2") numstyle("graph_aspect 0") margin("combine_region none" "combinegraph medsmall") areastyle("combine_plotregion plotregion" "combine_iplotregion none" "combinegraph background" "combinegraph_inner none") plotregionstyle("combinegraph matrixgraph" "combineregion combineregion") special("combine_slope1 .5" "combine_knot1 3" "combine_slope2 1") 
                        
                        brewscheme, schemename("your scheme file name") allst("category10") allc(7) themefile(smpanels)
                        You'd want to modify the arguments for the brewtheme command since those are just the default values but this is generally the way you would approach things to create a customized theme/scheme file. One way to think of the two commands is that brewtheme creates the global (e.g., graph independent) settings/config file and brewscheme consumes it in order to specify the settings for graph specific aesthetics (e.g., colors for different types of graphs, etc...). Once a theme file is created you can use it with any scheme files you create, which should make it much easier to keep specific graph features/settings consistent across projects where you may have a need to create graphs with different color palettes (e.g., for branding purposes, organizational publication standards, etc...). Hope this helps.

                        Comment


                        • #13
                          This is extremely useful, thank you so much!

                          Comment

                          Working...
                          X