Announcement

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

  • Color intensity in graphs

    Does anyone have a good sense (technical and/or aesthetic) why Stata defaults to a fill intensity under 100% for certain –twoway– graphs (e.g. bar, area, etc., but not hist)?

    For instance compare the output of the two (rather silly) graphs produced by this code:
    Code:
    sysuse auto
    tw hist rep78, discrete fcol(ebblue) lcol(ebblue*1.25) sch(sj)
    tw bar foreign rep78, fcol(ebblue) lcol(ebblue*1.25) sch(sj)
    If one enters graph editor with the second of these graphs still in memory one will see that the fill intensity is 80%.

    The default intensity can be overridden with the –fintensity()– option, but why the default intensity is not 100% is what baffles me.

    From what I can tell this does not appear to be a scheme-specific issue.

  • #2
    I guess two programmers wrote them separately.

    Comment


    • #3
      John, I reproduced your example in Stata/MP 16.1. With scheme(sj) and fcolor(ebblue) in both commands, the histogram uses 100% fill intensity (#008BBC in the exported SVG), while twoway bar uses 80% (#33A2C9). Stata treats fill color and fill intensity as separate settings. When fintensity() is omitted, each plot uses the intensity it gets from the scheme. Stata Graphics Reference Manual, barlook options (https://www.stata.com/manuals/g-3barlook_options.pdf)

      The installed scheme files show how that happens. sj includes s2mono, which includes s2color. Stata therefore starts with s2color and applies any overrides from s2mono and then sj. In this example, the histogram uses its dedicated entry, intensity histogram full. The first bar plot has no dedicated intensity entry under p1bar, so it falls back to the shared plot setting, intensity p inten80. I confirmed the fallback by adding intensity p inten40 to a test scheme that inherits sj. The bar fill changed to 40%, and the histogram stayed at 100%. Stata Graphics Reference Manual, shadestyle (https://www.stata.com/manuals/g-4shadestyle.pdf)

      That explains how the two plots get different intensities. The design question remains. Why was the shared default set to 80% while the histogram was given 100%? Vince Wiggins (StataCorp) of StataCorp confirmed the 80% default for twoway bar in a 2005 Statalist reply. If Vince or anyone else involved in the graphics design remembers how those values were chosen, I’d be interested to hear the story. Vince Wiggins’s 2005 Statalist reply (https://www.stata.com/statalist/arch.../msg00002.html)
      Click image for larger version

Name:	01_scheme.png
Views:	1
Size:	103.8 KB
ID:	1788269

      Click image for larger version

Name:	02_inheritance.png
Views:	1
Size:	100.7 KB
ID:	1788270

      Click image for larger version

Name:	03_fill_color.png
Views:	1
Size:	94.9 KB
ID:	1788271

      Code:
      * Run from the graphcolordensity directory, or pass its path as an argument.
      args outdir
      if `"`outdir'"' == "" local outdir "."
      capture mkdir "`outdir'/figures"
      
      preserve
      sysuse auto, clear
      tempname hsj bsj hs2 bs2 fig1 fig2 fig3 baseline bar40 p40 specific
      
      * Figure 1. Keep fcolor() and lcolor() fixed while selecting the scheme.
      foreach scheme in sj s2color {
          local histname `hsj'
          local barname `bsj'
          if "`scheme'" == "s2color" {
              local histname `hs2'
              local barname `bs2'
          }
          twoway histogram rep78, discrete fcolor(ebblue) lcolor(ebblue*1.25) ///
              scheme(`scheme') title("Histogram | `scheme'") name(`histname')
          twoway bar foreign rep78, fcolor(ebblue) lcolor(ebblue*1.25) ///
              scheme(`scheme') title("Twoway bar | `scheme'") name(`barname')
      }
      graph combine `hsj' `bsj' `hs2' `bs2', cols(2) xsize(9) ysize(6) ///
          scheme(sj) graphregion(color(white)) name(`fig1')
      graph export "`outdir'/figures/01_scheme.png", width(1800) replace
      
      * Figure 2. Add overrides in temporary schemes that inherit sj.
      tempfile schemefolder
      mkdir "`schemefolder'"
      adopath ++ "`schemefolder'"
      tempname handle
      foreach key in bar p p1bar {
          file open `handle' using "`schemefolder'/scheme-demo_`key'.scheme", write text
          file write `handle' "#include sj" _n
          file write `handle' "intensity `key' inten40" _n
          if "`key'" == "p1bar" file write `handle' "intensity p inten60" _n
          file close `handle'
      }
      
      local fillopts fcolor(ebblue) lcolor(ebblue*1.25)
      twoway bar foreign rep78, `fillopts' scheme(sj) ///
          title("sj") subtitle("80%") name(`baseline')
      twoway bar foreign rep78, `fillopts' scheme(demo_bar) ///
          title("intensity bar inten40") subtitle("80%") name(`bar40')
      twoway bar foreign rep78, `fillopts' scheme(demo_p) ///
          title("intensity p inten40") subtitle("40%") name(`p40')
      twoway bar foreign rep78, `fillopts' scheme(demo_p1bar) ///
          title("p1bar = 40 | p = 60") subtitle("40%") name(`specific')
      graph combine `baseline' `bar40' `p40' `specific', cols(2) xsize(9) ysize(6) ///
          scheme(sj) graphregion(color(white)) name(`fig2')
      graph export "`outdir'/figures/02_inheritance.png", width(1800) replace
      
      adopath - "`schemefolder'"
      foreach key in bar p p1bar {
          erase "`schemefolder'/scheme-demo_`key'.scheme"
      }
      rmdir "`schemefolder'"
      
      * Figure 3. Vary the base color and the intensity independently.
      local panels
      foreach color in ebblue orange {
          foreach level in 100 80 {
              tempname panel
              twoway bar foreign rep78, scheme(sj) fcolor(`color') ///
                  fintensity(`level') lcolor(gs6) ///
                  title("`color' | `level'%") name(`panel')
              local panels `panels' `panel'
          }
      }
      graph combine `panels', cols(2) xsize(9) ysize(6) ///
          scheme(sj) graphregion(color(white)) name(`fig3')
      graph export "`outdir'/figures/03_fill_color.png", width(1800) replace
      
      graph drop `hsj' `bsj' `hs2' `bs2' `fig1' `fig2' `fig3' ///
          `baseline' `bar40' `p40' `specific' `panels'
      restore
      Last edited by Choonjoo Lee; 21 Nov 2026, 14:39.

      Comment

      Working...
      X