Announcement

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

  • Dynamically set graph combine options

    Hi, i want to combine many graphs into one with graph combine, but number of the graphs is not constant as it is result of other process. Problem is that graph combine for most part looks ugly unless i fine tune its options to the number of the graphs (and also their length - meaning size of x axe that can also change). Here is small example that demonstrates my issue, i need to put many if else conditions in order to get something readable but it gets very tedious and in my case i would need too many of these conditions in order to get graphs that look as i want. Is there a way to make it automatic, so that for example aspect ratio of x and y axe is always the same no matter how many graphs i want to combine (and also relative fond size), or can i somehow make it as a function of graph sizes (local s)? Thanks for help

    Code:
    sysuse auto
    
    
    local size 5 15 22 88
    foreach s of local size {
    
    local graphs ""
    forval i = 1/`s' {
      scatter mpg weight, name(g`i', replace) nodraw
      local graphs "`graphs' g`i'"
    }
    
    if `s' < 10 {
        graph combine `graphs', col(3) xsize(5) ysize(5) iscale(*1)
    }
    else if `s'    >=10 & `s'<50 {
        graph combine `graphs', col(3) xsize(5) ysize(10) iscale(*1)
    }
    else {
        graph combine `graphs', col(3) xsize(3) ysize(20) iscale(*2)
    }
    
    graph export "size`s'.pdf", replace
    
    }





Working...
X