R语言 获取指定色调的十六进制代码 – rgb()函数
R语言中的 rgb() 函数用于在0和1之间指定红、绿、蓝三色的阴影。红、绿、蓝三色的阴影也可以在0到255之间指定。但在使用这个范围时,会有一个附加参数max=255。该函数返回指定色阶的相应十六进制代码。
语法: rgb(a, b, c, max = 255)
参数:
a: 红色的阴影
b: 绿色的阴影
c: 蓝色的阴影
max: 添加的参数max=255
例1:
# R program to illustrate
# rgb function
# Calling the rgb() function with
# shade of color between 0 to 1
rgb(0, 1, 0.5)
rgb(0.9, 0.7, 0.8)
rgb(0, 0.7, 1)
rgb(0, 0, 0)
rgb(1, 1, 1)
输出:
[1] "#00FF80"
[1] "#E6B3CC"
[1] "#00B3FF"
[1] "#000000"
[1] "#FFFFFF"
例2:
# R program to illustrate
# rgb function
# Calling the rgb() function with
# shade of color between 0 and 255
# with added argument max = 255
rgb(0, 0, 0, max = 255)
rgb(5, 7, 60, max = 255)
rgb(255, 255, 255, max = 255)
输出:
[1] "#000000"
[1] "#05073C"
[1] "#FFFFFF"