R 語言中的 col2rgb() 函數用於將 R 顏色轉換為 RGB(紅/綠/藍)。
用法: col2rgb(col)
參數:
col:三種 R 顏色規範中任何一種的向量,即顏色名稱(由 colors() 列出)、形式為 “#rrggbb” 或 “#rrggbbaa” 的十六進製字符串,或正整數 i 表示 palette()[i]
範例1:
# R program to illustrate
# col2rgb function
# Calling the col2rgb() function
col2rgb("# 08a0ff")
col2rgb("peachpuff")
col2rgb(1:8)
col2rgb(paste0("gold", 1:4))輸出:
[, 1]
red 8
green 160
blue 255
[, 1]
red 255
green 218
blue 185
[, 1] [, 2] [, 3] [, 4] [, 5] [, 6] [, 7] [, 8]
red 0 255 0 0 0 255 255 190
green 0 0 205 0 255 0 255 190
blue 0 0 0 255 255 255 0 190
[, 1] [, 2] [, 3] [, 4]
red 255 238 205 139
green 215 201 173 117
blue 0 0 0 0
範例2:
# R program to illustrate
# col2rgb function
# Calling the col2rgb() function
col2rgb(c(blu = "royalblue", reddish = "tomato"))
col2rgb(c(red = "red", hex = "# abcdef"))
col2rgb(c(palette = 1:3))輸出:
blu reddish
red 65 255
green 105 99
blue 225 71
red hex
red 255 171
green 0 205
blue 0 239
palette1 palette2 palette3
red 0 255 0
green 0 0 205
blue 0 0 0
相關用法
- R語言 rgb2hsv()用法及代碼示例
- R語言 topo.colors()用法及代碼示例
- R語言 cm.colors()用法及代碼示例
- R語言 terrain.colors()用法及代碼示例
- R語言 rgb()用法及代碼示例
- R語言 heat.colors()用法及代碼示例
- R語言 charToRaw()用法及代碼示例
- R語言 deg2rad()用法及代碼示例
- R語言 rad2deg()用法及代碼示例
- R語言 type.convert()用法及代碼示例
- R語言 utf8ToInt()用法及代碼示例
- R語言 as.binary()用法及代碼示例
- R語言 rainbow()用法及代碼示例
- R語言 order()用法及代碼示例
- R語言 lgamma()用法及代碼示例
- R語言 trigamma()用法及代碼示例
- R語言 qcauchy()用法及代碼示例
- R語言 qlogis()用法及代碼示例
- R語言 qlnorm()用法及代碼示例
- R語言 qpois()用法及代碼示例
- R語言 qnbinom()用法及代碼示例
- R語言 ecdf()用法及代碼示例
- R語言 pf()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Convert a Color to its rgb value in R Programming – col2rgb() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
