Bonjour,
Plusieurs pointeurs utiles : le package RColorBrewer :
http://cran.r-project.org/src/contrib/D ... rewer.html
Mais sinon, pour construire une palette a la main, je conseille la fonction colorRampPalette, par exemple :
Code : Tout sélectionner
R> myPal <- colorRampPalette( c("green", "red") )
R> myPal( 10 )
[1] "#00FF00" "#1CE200" "#38C600" "#55AA00" "#718D00" "#8D7100" "#AA5500"
[8] "#C63800" "#E21C00" "#FF0000"
J'ai aussi cette petite fonction qui est utile pour visualiser une palette dans l'espace RGB. La fonction necessite le package RGL.
Code : Tout sélectionner
colorcube <- function(
cols, #@ colors to show
refresh = TRUE, #@ (logical) clean the scene before drwaing the colours
radius=c(4, 7, 5), #@ (length-3 vector) radius of the colours, colours knots,
#- and edges
interp=TRUE, #@ (logical) are we interpolating between the colours
nc = 500, #@ number of colours (only used if interp=TRUE)
corners = TRUE, #@ (logical) draws the cube corners
... #@ extra arguments to pass to colorRampPalette if interp=TRUE
){
knot.cols <- NULL
knot.mat <- NULL
if(interp) {
knot.cols <- cols
knot.mat <- col2rgb(knot.cols)
cols <- colorRampPalette(cols, ...)(nc)
}
rgbmat <- col2rgb(cols)
if(refresh) rgl.clear()
spheres3d( rgbmat[1,], rgbmat[2, ], rgbmat[3,] , col = cols, radius = radius[1])
if(interp) spheres3d( knot.mat[1,], knot.mat[2, ], knot.mat[3,] ,
col = knot.cols, radius = radius[2])
if(corners){
gri <- expand.grid(c(0, 256), c(0, 256), c(0, 256))
cor.col <- rgb(gri[,1], gri[,2], gri[,3], max=256)
cor.mat <- col2rgb(cor.col)
spheres3d( cor.mat[1,], cor.mat[2, ], cor.mat[3,] ,
col = cor.col, radius = radius[3])
}
for(i in (0:2)*128){
for(j in (0:2)*128){
rgl.lines( x = c(0, 256, j, j),
y = c(j,j, 0, 256),
z = c(i, i,i, i), col = "black" )
}
}
gr <- expand.grid( z = c(0, 256), x= c(0, 256) , y = c(0, 256))
rgl.lines( x=gr$x, y=gr$y, z=gr$z, col="black")
# text3d( 128, 128, 300, deparse(substitute(cols)) , col="black")
out <- list(cols=cols, rgbmat = rgbmat, knot.cols=knot.cols, knot.mat=knot.mat)
invisible(out)
}
Par exemple :
Code : Tout sélectionner
colorcube( c("green", "red") )
colorcube( c("green", "red") , interpolate = "splines")
J'espere que ca peut aider.
Romain