删除颜色的透明度但保留颜色本身

ava*_*ava 2 r colors

我想删除颜色的透明度,但保留颜色本身。

例如,我喜欢绿色的透明版本,但我想要这种不透明的颜色。

library(scales)
show_col("green")
Run Code Online (Sandbox Code Playgroud)


alpha("green",0.3) -> nice_green
show_col(nice_green)
Run Code Online (Sandbox Code Playgroud)

创建于 2022 年 11 月 21 日,使用reprex v2.0.2

我想过使用lightenfromcolorspace但我得到了不同的果岭。

library(colorspace)
library(scales)
lighten("green",0.3) -> not_green_I_want
show_col(not_green_I_want)
Run Code Online (Sandbox Code Playgroud)

创建于 2022 年 11 月 21 日,使用reprex v2.0.2

dca*_*son 5

一种解决方案是检查名称中包含“绿色”的所有命名颜色,看看其中一种是否足够:

colors()[grep("green", colors())]   # Forty green colors
Run Code Online (Sandbox Code Playgroud)

更好的解决方案是转向色调/饱和度/明度颜色规范。这看起来很接近你想要的,但可能需要一些调整:

show_col(hsv(121/360, .4, 1))
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅手册页?hsv

  • 类似于 `ch <- rgb2hsv(col2rgb("green")); newcol <- hsv(h=ch["h",], v=ch["v",], s=0.3)` 似乎可以做到这一点,所以我认为 hsv 调整是可行的方法。 (2认同)