R and colors from another dimension
I like to have a "x vs. y"- plot in which the symbol colors represent a additional (or another :-) dimension z.
I’m sure that there are several ways to do that, however here is the way I understand.
Assume that x, y and z have the same length n :
n <- length(y)
At first I generate a vector from z (z will give the color) in the interval [0,1]
zp <- z - min(z) ## zp starts from 0 zpp <- zp/max(zp) ## zpp ends at 1
If I now multiply zpp by n I get a nice index vector which can be used together with the result produced by colorRampPalette():
cf <- colorRampPalette(c("blue","yellow","red"))
cf is a function. It’s argument is the length of the color vector which should be returned. Now put everything together:
Here is a complete example:
This is how it looks like: