Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 特定颜色的显示_R - Fatal编程技术网

R 特定颜色的显示

R 特定颜色的显示,r,R,我正在研究颜色分类。我正在初始化一个具有特定颜色的矩阵,以便得到一个16x16的红色、蓝色或绿色矩阵。代码如下: library(rgl) color1 <- function() { n <- 3 m <- 16 a <- list("numeric", n) wij <- matrix(list(), nrow = m, ncol = m) #Initailize the weight

我正在研究颜色分类。我正在初始化一个具有特定颜色的矩阵,以便得到一个16x16的红色、蓝色或绿色矩阵。代码如下:

 library(rgl)
    color1 <- function()
   {
      n <- 3
      m <- 16
      a <- list("numeric", n)
      wij <- matrix(list(), nrow = m, ncol = m)

      #Initailize the weight matrix
      for(x1 in 1:m)
      {
        for(x2 in 1:m)
        {
          a<-c(1,255,1)
          # a<- c(255,1,1)
          #a<-c(1,1,255)
          wij[[x1,x2]] <- a
          rgl.spheres(x=x1, y=x2, col=wij[[x1,x2]], radius = 1 )
        }
      }
    }    
    color1() 
库(rgl)

color1将函数中的最后一个命令更新为:

rgl.spheres(x=x1, y=x2, col=rgb(t(wij[[x1,x2]]), maxColorValue = 255), radius = 1 )
说明:
R中的颜色指定为与预定义颜色(
Colors()
)或十六进制RGB编码“#RRGGBB”对应的字符串。在
col=
参数中指定数字将从调色板返回颜色

cols <- function(a) image(1:5, 1, as.matrix(1:5), col=a, axes=FALSE , xlab="", ylab="")
a <- 1:5
cols(a)

因此,我们需要使用
RGB()
函数从RGB强度创建R颜色。该函数接受三个强度的矩阵。将向量强制转换为默认值为R的矩阵,该矩阵按列填充数据。我们需要一行强度,最简单的方法是变换矩阵

a <- rgb(t(a), maxColorValue = 255)
a
[1] "#01FF01"
cols(a)

a提供一个。您的代码中缺少函数
rgl.spheres
。很抱歉。我已经添加了这个功能,非常感谢。如果它能为您解决问题,请接受答案(左边的复选标记)。
a <- rgb(t(a), maxColorValue = 255)
a
[1] "#01FF01"
cols(a)