Announcement

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

  • Transparency in graphs not working with scheme-specific colors

    Hello everyone, I'm trying to produce a histogram in Stata 17 with the following attributes:
    1. using a custom scheme,
    2. explicitly declaring the bar color to be one of the default colors defined within the given scheme file
    3. adjusting the transparency of this bar color.
    According to my google search, this can be done using the following command:

    Code:
    hist mpg, fcolor("scheme p1%50") scheme(economist)
    and it works well as long as the scheme’s default colors (as defined in the corresponding scheme file) are sourced from the standard Stata color class:
    Code:
    color p1 maroon
    But, it does not work when the scheme’s default colors are defined as RGB:
    Code:
    color p1 "230 92 92"
    In the latter case, adjusting transparency fails. See the example below:

    Code:
    net install schemepack, from("https://raw.githubusercontent.com/asjadnaqvi/Stata-schemes/main/schemes/") replace
     
    sysuse auto, clear
     
    hist mpg, fcolor("230 92 92%50") scheme(neon)    name(g1,replace) title("with RGB color")
    hist mpg, fcolor("26 71 111%50") scheme(s2color) name(g2,replace) title("with RGB color")
     
    hist mpg, fcolor("scheme p1%50") scheme(neon)    name(g3,replace) title("with scheme pX color")
    hist mpg, fcolor("scheme p1%50") scheme(s2color) name(g4,replace) title("with scheme pX color")
     
    graph combine g1 g2 g3 g4
    Click image for larger version

Name:	Graph.jpg
Views:	1
Size:	36.4 KB
ID:	1681462


    The bottom-left chart is the one with failed transparency. I suspect the problem is that the color p1 in the corresponding scheme file is defined as an RGB in parentheses, and these parentheses mess up the fcolor("scheme p1%50") option.

    Would you happen to know whether there is a way to make the command below work properly?
    Code:
    hist mpg, fcolor("scheme p1%50") scheme(neon)

    Thank you,

    Jan


  • #2
    solved:

    Code:
    hist mpg, fcolor("`.__SCHEME.color.p1'%50") scheme(neon)

    Comment


    • #3
      alternative:
      Code:
      histogram price, scheme(neon) color(%50) pstyle(p2)

      Comment


      • #4
        Very elegant, thanks!

        Comment

        Working...
        X