Change transparency for non-default color

Viewed 38

I have created my own color using the following command:

colorpalette Red, luminate(0(10)100, level) nograph
return list
foreach x of numlist 1/10 {
    local color`x' `r(p`x')'
}

I can access and use these colors just fine, and the second color for example is

di "`color2'"
156 0 0

However, problems arise when I want to add transparency. Say I am overlaying two histograms and want to add transparency, if I do something like

twoway hist somevar, color("156 0 0"%30)

and here, it just ignores the %30 part. color(red%30) works fine, but color("`color2'"%30) does not.

How can I add transparency with self-created colors after the creation? I would prefer not to recreate the whole colorpalette everytime that I want to change the transparency.

1 Answers

Everything within quotes is treated as one object, so you need to include %30 within the quotes.

twoway hist price, color("156 0 0%30")
Related