I've been thinking hard about generating colour schemes for data. There's quite a bit of existing code scattered in various packages for playing with colours and colour palettes, but I can't find the sort of thing I'm after for applying colours to data...
To my mind a colour scheme is a mapping from data values to colours. There's a multitude of such mappings depending on the nature of the data. For example, for a factor you might want to map levels to unique colours. For numbers that run from -4 to +2 you might want to use a diverging colour palette centred on zero. This might be continuous in some colour space or composed of a small number of discrete colours, each of which covers a range of values. Or it could be piecewise continuous as used in topographic maps - less than zero is blue, zero to 400 goes from sandy yellow to grassy green, 400 to 1000 goes from grassy green to rocky brown, then suddenly you hit the ice and 1000 and upwards is white. Or you could have a multivariate mapping where (x,y,z) -> (r,g,b,a) in complex and non-linear ways. I see a set of factory functions that return colour scheme mapping functions that map data to colours, so you'd do: # unique colour for each factor level scheme1 = exactColours(data$f,someColours) # data$f is a factor, someColours is a vector of colour values plot(data$x,data$y,col=scheme1(data$f)) # topological map colouring scheme2 = continuousColours(list(-1000,"blue",0,"sandYellow",400,"grassGreen",1000,"rockBrown",1000,"white",10000)) # or something... plot(data$x,data$y,col=scheme2(data$height)) Now just because I can't find existing functions like this doesn't mean they don't exist. There's stuff in plotrix, colorspace, RColorBrewer etc for creating palettes but then the user is left to their own devices to map colours to data values. Does this kind of thing sound useful? Has it been done? Is it worth doing? Anybody got any better ideas? Barry ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel