[R] Confused about specifying plot colors as RGB values

Paul Roebuck roebuck at odin.mdacc.tmc.edu
Fri Sep 17 22:32:41 CEST 2004


Based on reading 'rgb' documentation, I would have thought
the following would have produced identical results. Can
someone explain how to make this happen? I need to be able
to specify an array of rgb values for the 'col' parameter.


colnames.col <- c("black", "red", "blue", "green")
colnames.rgb <- apply(as.matrix(colnames.col), 1, col2rgb)
dimnames(colnames.rgb)[[2]] <- colnames.col

baseline <- 1:32
offset2 <- 2*baseline
offset3 <- 3*baseline
offset4 <- 4*baseline
offsets <- cbind(offset2, offset3, offset4)

# Produces expected result
X11()
matplot(baseline, col = colnames.col[1], type = "l")
matlines(offsets, col = colnames.col[-1])

# Displays a ??yellow?? line
X11()
matplot(baseline, col = as.matrix(colnames.rgb[,1]), type = "l")
matlines(offsets, col = colnames.rgb[,-1])


----------------------------------------------------------
SIGSIG -- signature too long (core dumped)




More information about the R-help mailing list