Set colors in a PCA plot based on a gradient vector
On 11/06/2009 03:21 AM, Joel F?rstenberg-H?gg wrote:
Hi all, I'm making a PCA plot with eight variables (columns taken from a larger data frame "fieldTrial0809[idx,c(39:46)]"). I then want the symbols in the plot to be colored as a gradient from red to blue, depending on the value of another column in "fieldTrial0809[idx, c(48)]" containg temperatures from -12.1 to -5.4. I don't want to use the heat.colors(n) function, because then I just get colors from red to yellow... I've created a vector "colTemperature" with 12 colors and I've also made a new vector "tempACC", based on the values of "fieldTrial0809[idx, c(48)]" with 12 levels. What I don't know, is how to incorporate this vector in the text() function below:
df=fieldTrial0809[idx,c(39:46)]
PC=prcomp (df[,1:8])
hcl=hclust(dist(df))
plot(PC$x[,1],PC$x[,2], col="white", main="8 variables")
text(PC$x[,1],PC$x[,2], labels=cutree(hcl,8), col=cutree(hcl,8)) # Change this, but how???
library(plotrix)
text(...,col=color.scale(fieldTrial0809[idx,48],
extremes=c("red","blue"))
Finally, I've got another question, how do you decide how many components to use in "text(... labels=cutree(hcl,8), ...)"? Do you try with different values until i looks nice or what..?
As in so many other areas of life, beauty is in the eye of the beholder. Jim