如何在 R 中从颜色代码获取颜色名称?
要从颜色代码获取颜色名称,我们可以使用 plotrix 包的 color_id 函数。如果我们有一个颜色代码向量,比如说 x,那么可以使用命令 sapply(x,color.id) 找到颜色名称。
示例
> x<-c("#FF0000","#FF1F00","#FF3D00","#FF5C00","#FF7A00","#FF9900","#FFB800","#FFD600","#FFF500","#EBFF00","#CCFF00","#ADFF00","#8FFF00","#70FF00","#52FF00","#33FF00","#14FF00","#00FF0A","#00FF29","#00FF47","#00FF66","#00FF85","#00FFA3","#00FFC2","#00FFE0","#00FFFF","#00E0FF","#00C2FF","#00A3FF","#0085FF","#0066FF","#0047FF","#0029FF","#000AFF","#1400FF","#3300FF","#5200FF","#7000FF","#8F00FF","#AD00FF","#CC00FF","#EB00FF","#FF00F5","#FF00D6","#FF00B8","#FF0099","#FF007A","#FF005C","#FF003D","#FF001F") > x
输出
[1] "#FF0000" "#FF1F00" "#FF3D00" "#FF5C00" "#FF7A00" "#FF9900" "#FFB800" [8] "#FFD600" "#FFF500" "#EBFF00" "#CCFF00" "#ADFF00" "#8FFF00" "#70FF00" [15] "#52FF00" "#33FF00" "#14FF00" "#00FF0A" "#00FF29" "#00FF47" "#00FF66" [22] "#00FF85" "#00FFA3" "#00FFC2" "#00FFE0" "#00FFFF" "#00E0FF" "#00C2FF" [29] "#00A3FF" "#0085FF" "#0066FF" "#0047FF" "#0029FF" "#000AFF" "#1400FF" [36] "#3300FF" "#5200FF" "#7000FF" "#8F00FF" "#AD00FF" "#CC00FF" "#EB00FF" [43] "#FF00F5" "#FF00D6" "#FF00B8" "#FF0099" "#FF007A" "#FF005C" "#FF003D" [50] "#FF001F"
加载 plotrix 包,查找 x 中颜色代码的颜色名称 −
> library(plotrix) > sapply(x,color.id)
输出
$`#FF0000` [1] "red" "red1" $`#FF1F00` [1] "red" "red1" $`#FF3D00` [1] "orangered" "orangered1" $`#FF5C00` [1] "orangered" "orangered1" $`#FF7A00` [1] "darkorange1" $`#FF9900` [1] "orange" "orange1" $`#FFB800` [1] "darkgoldenrod1" $`#FFD600` [1] "gold" "gold1" $`#FFF500` [1] "yellow" "yellow1" $`#EBFF00` [1] "yellow2" $`#CCFF00` [1] "yellow2" $`#ADFF00` [1] "chartreuse" "chartreuse1" $`#8FFF00` [1] "chartreuse" "chartreuse1" $`#70FF00` [1] "lawngreen" $`#52FF00` [1] "chartreuse2" $`#33FF00` [1] "green" "green1" $`#14FF00` [1] "green" "green1" $`#00FF0A` [1] "green" "green1" $`#00FF29` [1] "green" "green1" $`#00FF47` [1] "springgreen2" $`#00FF66` [1] "springgreen2" $`#00FF85` [1] "springgreen" "springgreen1" $`#00FFA3` [1] "mediumspringgreen" $`#00FFC2` [1] "mediumspringgreen" $`#00FFE0` [1] "cyan2" $`#00FFFF` [1] "cyan" "cyan1" $`#00E0FF` [1] "turquoise2" $`#00C2FF` [1] "deepskyblue" "deepskyblue1" $`#00A3FF` [1] "deepskyblue2" $`#0085FF` [1] "dodgerblue" "dodgerblue1" $`#0066FF` [1] "dodgerblue2" $`#0047FF` [1] "blue" "blue1" $`#0029FF` [1] "blue" "blue1" $`#000AFF` [1] "blue" "blue1" $`#1400FF` [1] "blue" "blue1" $`#3300FF` [1] "blue" "blue1" $`#5200FF` [1] "purple3" $`#7000FF` [1] "darkviolet" $`#8F00FF` [1] "purple" $`#AD00FF` [1] "purple" $`#CC00FF` [1] "magenta2" $`#EB00FF` [1] "magenta2" $`#FF00F5` [1] "magenta" "magenta1" $`#FF00D6` [1] "magenta2" $`#FF00B8` [1] "deeppink" "deeppink1" $`#FF0099` [1] "deeppink" "deeppink1" $`#FF007A` [1] "deeppink2" $`#FF005C` [1] "deeppink2" $`#FF003D` [1] "firebrick1" $`#FF001F` [1] "red" "red1"$`#FF0000` [1] "red" "red1" $`#FF1F00` [1] "red" "red1" $`#FF3D00` [1] "orangered" "orangered1" $`#FF5C00` [1] "orangered" "orangered1" $`#FF7A00` [1] "darkorange1" $`#FF9900` [1] "orange" "orange1" $`#FFB800` [1] "darkgoldenrod1" $`#FFD600` [1] "gold" "gold1" $`#FFF500` [1] "yellow" "yellow1" $`#EBFF00` [1] "yellow2" $`#CCFF00` [1] "yellow2" $`#ADFF00` [1] "chartreuse" "chartreuse1" $`#8FFF00` [1] "chartreuse" "chartreuse1" $`#70FF00` [1] "lawngreen" $`#52FF00` [1] "chartreuse2" $`#33FF00` [1] "green" "green1" $`#14FF00` [1] "green" "green1" $`#00FF0A` [1] "green" "green1" $`#00FF29` [1] "green" "green1" $`#00FF47` [1] "springgreen2" $`#00FF66` [1] "springgreen2" $`#00FF85` [1] "springgreen" "springgreen1" $`#00FFA3` [1] "mediumspringgreen" $`#00FFC2` [1] "mediumspringgreen" $`#00FFE0` [1] "cyan2" $`#00FFFF` [1] "cyan" "cyan1" $`#00E0FF` [1] "turquoise2" $`#00C2FF` [1] "deepskyblue" "deepskyblue1" $`#00A3FF` [1] "deepskyblue2" $`#0085FF` [1] "dodgerblue" "dodgerblue1" $`#0066FF` [1] "dodgerblue2" $`#0047FF` [1] "blue" "blue1" $`#0029FF` [1] "blue" "blue1" $`#000AFF` [1] "blue" "blue1" $`#1400FF` [1] "blue" "blue1" $`#3300FF` [1] "blue" "blue1" $`#5200FF` [1] "purple3" $`#7000FF` [1] "darkviolet" $`#8F00FF` [1] "purple" $`#AD00FF` [1] "purple" $`#CC00FF` [1] "magenta2" $`#EB00FF` [1] "magenta2" $`#FF00F5` [1] "magenta" "magenta1" $`#FF00D6` [1] "magenta2" $`#FF00B8` [1] "deeppink" "deeppink1" $`#FF0099` [1] "deeppink" "deeppink1" $`#FF007A` [1] "deeppink2" $`#FF005C` [1] "deeppink2" $`#FF003D` [1] "firebrick1" $`#FF001F` [1] "red" "red1"
广告