Announcement

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

  • Passing "graph query, schemes" results to macro

    Colleagues,

    I would like to pass the list of installed styles, which is returned via the graph query, schemes to a local macro. I'm expecting to use in the code below
    Code:
    // Provide scheme list
    local listschemes mrc s2color s2mono s2manual s2gmanual s2gcolor s1color ///
                     s1mono    s1rcolor s1manual sj economist s2color8 burd burd10 ///
                     burd11 burd3 burd4 burd5 burd6 burd7 burd8 burd9 lean1 ///
                     lean2 rbn1mono rbn2mono rbn3mono rbn4mono sol tufte vg_blue ///
                     vg_brite vg_lgndc vg_lgndm vg_outc vg_outm vg_palec ///
                     vg_palem vg_past vg_rose vg_s1c vg_s1m vg_s2c vg_s2m ///
                     vg_samec vg_samem vg_teal
    
    // Loop through the schemes
    foreach lscheme of local listschemes {
    
    xtline (...) chart routine (...)
            scheme(`lscheme') ///
            t2title("Used colour scheme: {bf:`lscheme'}", size(medsmall) box) ///
            name(scheme_`lscheme', replace)
        
        * Save graph
        graph save scheme_`lscheme', replace
        graph export scheme_`lscheme'.tif, replace
    }
    Presently, I simply typed available styles to the listschemes local macro. Naturally, if I'm going to download new schemes I will have to add them to the macro, I would rather avoid doing that and source the style names automatically. My ambition is to produce a series of charts illustrating what can be quickly achieved with use of the available colour schemes, so people can pick what they want to see in a report.
    Last edited by Konrad Zdeb; 21 Oct 2014, 08:29. Reason: Tags, as they didn't save when posting.
    Kind regards,
    Konrad
    Version: Stata/IC 13.1

  • #2
    Konrad,

    It doesn't appear that graph query, schemes is set up to do that automatically, but based on Stata's code for graph query, schemes, it looks like it would not be hard to do. The following is based on the relevant bit of code from gr_query.ado:

    Code:
    stypop populate __STYLES scheme .scheme
    forvalues i = 1/`.__STYLES.scheme.arrnels' {
            local el `el' `.__STYLES.scheme[`i']'
    }
    di "`el'"
    Regards,
    Joe

    Comment


    • #3
      Joe,

      Thanks very much for the code. It works like a charm. I used the code below to generate a series of histograms.
      Code:
      sysuse auto
      stypop populate __STYLES scheme .scheme
      forvalues i = 1/`.__STYLES.scheme.arrnels' {
              local el `el' `.__STYLES.scheme[`i']'
      }
      di "`el'"
      foreach lscheme of local el {
          hist price, scheme(`lscheme') percent name(`lscheme')
          }
      Interestingly, it appears that I have some schemes installed that do not work properly:

      Code:
      . sysuse auto
      (1978 Automobile Data)
      
      . stypop populate __STYLES scheme .scheme
      
      . forvalues i = 1/`.__STYLES.scheme.arrnels' {
        2.         local el `el' `.__STYLES.scheme[`i']'
        3. }
      
      . di "`el'"
      s2color s2mono s2manual s2gmanual s2gcolor s1color s1mono s1rcolor s1manual sj economist s2color8
      >  burd burd10 burd11 burd3 burd4 burd5 burd6 burd7 burd8 burd9 vg_blue vg_brite vg_lgndc vg_lgnd
      > m vg_outc vg_outm vg_palec vg_palem vg_past vg_rose vg_s1c vg_s1m vg_s2c vg_s2m vg_samec vg_sam
      > em vg_size vg_teal
      
      . foreach lscheme of local el {
        2.         hist price, scheme(`lscheme') percent name(`lscheme')
        3.         }
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (bin=8, start=3291, width=1576.875)
      (note:  graphstyle graph not found in scheme, default attributes used)
      (note:  graphstyle not found in scheme, default attributes used)
      (note:  color background not found in scheme, default attributes used)
      (note:  plotregionstyle twoway not found in scheme, default attributes used)
      (note:  plotregionstyle not found in scheme, default attributes used)
      option seriesid() not allowed
      r(198);
      
      end of do-file
      
      r(198);
      This is interestingly odd as I didn't manufacture my own styles but only installed what is available.
      Code:
      . graph query, schemes
      
      Available schemes are
      
          s2color        see help scheme_s2color
          s2mono         see help scheme_s2mono
          s2manual       see help scheme_s2manual
          s2gmanual      see help scheme_s2gmanual
          s2gcolor       see help scheme_s2gcolor
          s1color        see help scheme_s1color
          s1mono         see help scheme_s1mono
          s1rcolor       see help scheme_s1rcolor
          s1manual       see help scheme_s1manual
          sj             see help scheme_sj
          economist      see help scheme_economist
          s2color8       see help scheme_s2color8
          burd           see help scheme_burd
          burd10
          burd11
          burd3
          burd4
          burd5
          burd6
          burd7
          burd8
          burd9
          vg_blue
          vg_brite
          vg_lgndc
          vg_lgndm
          vg_outc
          vg_outm
          vg_palec
          vg_palem
          vg_past
          vg_rose
          vg_s1c
          vg_s1m
          vg_s2c
          vg_s2m
          vg_samec
          vg_samem
          vg_size
          vg_teal
      Kind regards,
      Konrad
      Version: Stata/IC 13.1

      Comment


      • #4
        Konrad,

        Glad to help. Perhaps the extra schemes are things that got downloaded from elsewhere without you knowing it (e.g., as part of some other downloaded package). For example, the vg_* schemes come from the supplemental materials for the book A Visual Guide to Stata Graphics. The burd schemes look like they are available from SSC (see for example http://fmwww.bc.edu/repec/bocode/s/scheme-burd.scheme).

        Regards,
        Joe

        Comment


        • #5
          See also https://github.com/briatte/burd

          My one small tip here is to start with s1color. The blue backdrop of s2color is distinctive, but a distraction in many circumstances, e.g. when students mix graphics from quite different software. Locally, it is set as the default.

          Comment


          • #6
            Joe/Nick,

            Thanks for your comments. That's true I was installing the visual guide schemes. I forked the burd repository, very useful.
            Kind regards,
            Konrad
            Version: Stata/IC 13.1

            Comment

            Working...
            X