Announcement

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

  • Specify different color palettes when using -graph combine-?

    Dear all,

    I am using Ben Jann's user written -grstyle- package from SSC to create graphs with different color palettes. I would like to combine two graphs but retain the different color palettes used when they were originally created. Instead what happens is the color palette from the first graph listed in the graph combine command is applied to the second/remaining graphs.

    Is there a way to specify color palettes (or other grstyle attributes) when combining graphs? My eventual goal is to produce 8-10 sets of graphs for different outcome indicators by region, wealth quintile, and urban/rural residence, but to have all of the graphs that are by wealth quintile using the ptol palette, to help orient readers a bit better. (Merits of this approach may be debatable but are not my primary question!)

    An example:
    Code:
    sysuse auto, clear
    ssc install grstyle // if not already installed
    
    grstyle init
    
    sort weight
    
        * by foreign:
             grstyle set color Set2
            foreach var of varlist price mpg {
                twoway connected `var' weight if foreign==1, lw(thick) || connected `var' weight if foreign==0, lw(thick) 
            graph save foreign_`var'.gph, replace
            }
    
        * by rep78:
        grstyle set color ptol
            foreach var of varlist price mpg {
                twoway connected `var' weight if rep78==1, lw(thick) || connected `var' weight if rep78==2, lw(thick) || connected `var' weight if rep78==3, lw(thick) || connected `var' weight if rep78==4, lw(thick) || connected `var' weight if rep78==5, lw(thick) 
            graph save rep78_`var'.gph, replace
            }
            
        
    graph combine rep78_price_trend.gph foreign_price_trend.gph // both graphs have Set2 palette
    graph combine foreign_price_trend.gph rep78_price_trend.gph // both graphs have ptol palette
    The -graph combine- help file notes that one can specify a commonscheme (and that if not specified, the graphs will retain their original scheme), but I may be not familiar enough with schemes, as when I substitute e.g. "set scheme s1mono" and "set scheme economist" for the two grstyle commands above, the same result occurs -- both graphs have the s1mono scheme.

    thank you,
    Hannah

  • #2
    The reason why this problem occurs is that essentially -grstyle set color- is to modify colors of current scheme, not to replace the scheme itself with another one. i.e., in both loops you are using the same s2color(factory default) scheme. The solution is simple, you just need to specify the scheme name when using -grsryle init- as follows:
    Code:
    * by foreign:
        grstyle init Set2 , replace
        grstyle set color Set2
        foreach var of varlist price mpg {
            twoway connected `var' weight if foreign==1, lw(thick) || connected `var' weight if foreign==0, lw(thick) 
        graph save foreign_`var'.gph, replace
        }
    
    * by rep78:
        grstyle init ptol , replace
        grstyle set color ptol
        foreach var of varlist price mpg {
            twoway connected `var' weight if rep78==1, lw(thick) || connected `var' weight if rep78==2, lw(thick) || connected `var' weight if rep78==3, lw(thick) || connected `var' weight if rep78==4, lw(thick) || connected `var' weight if rep78==5, lw(thick) 
        graph save rep78_`var'.gph, replace
        }
    Then graphs in first loop will using the scheme named Set2 and second loop will using the scheme named ptol, so -graph combine- will display graphs with different colors.

    Comment


    • #3
      Thank you for the quick reply. When I make those edits to the code, however, the resulting combined graphs are now both in the default Stata colors -- which is not what I am aiming for. As far as I understood, Set2 and ptol are not Stata schemes, but rather colorpalettes found within grstyle. Perhaps I am missing something?

      Comment


      • #4
        Yes, Set2 and ptol are colorpalettes. But by specifying scheme names with -grstyle init- command, you will create a scheme named Set2/ptol in your working directory. This scheme will first be identical to s2color(factory default) but soon modified to have Set2/ptol colors by -grstyle set color-. (note: -grstyle init- includes -grstyle clear- so you will have s2color again when you run -grstyle init- again). Since the code works properly in my environment, I cannot guess what might be the source of your problem...

        Comment


        • #5
          Thank you JeongHoon, knowing that it is working for you is encouraging. I will continue to dig into this.

          Comment

          Working...
          X