我有大约每50个人的三个因素(SET1,SET2和SET3)。 对于SET1,SET2,并且SET3的值是 “A”, “B”, “C”。 我想使这些数据的热图类情节,但具有图例示与值相关联的颜色(例如,A =“红色”,B =“蓝色”,C =“黑”)。 有什么建议?
谢谢。
我有大约每50个人的三个因素(SET1,SET2和SET3)。 对于SET1,SET2,并且SET3的值是 “A”, “B”, “C”。 我想使这些数据的热图类情节,但具有图例示与值相关联的颜色(例如,A =“红色”,B =“蓝色”,C =“黑”)。 有什么建议?
谢谢。
我决定这将是easist(反正我)与GGPLOT2接近这一点:
#recreate a data set
dat <- data.frame(person=factor(paste0("id#", 1:50),
levels =rev(paste0("id#", 1:50))), matrix(sample(LETTERS[1:3], 150, T), ncol = 3))
library(ggplot2); library(reshape2)
dat3 <- melt(dat, id.var = 'person')
ggplot(dat3, aes(variable, person)) + geom_tile(aes(fill = value),
colour = "white") + scale_fill_manual(values=c("red", "blue", "black"))
类似的情节也可以与基础制造的图形。 下面是使用碱的一种方法image
的功能。 该样品具有分类响应,而不是数字的。
dx <- data.frame( Tasks = c('1','2','3','4'),
Phase1 = c('Done','Done','Done','WIP'),
Phase2 = c('WIP','Done','Done',''),
Phase3 = c('','WIP','Done',''))
ff<-factor(as.matrix(dx[,2:4]),
levels=c("Done","WIP",""),
labels=c("done","wip","-empty-")
)
fx<-matrix(as.numeric(ff), ncol=ncol(dx)-1)
#use labels to assign colors
col<-c(done="darkgreen",wip="orange","-empty-"="black")
imgflip<-function(x) {t(x[nrow(x):1,])}
image(imgflip(fx),
breaks=(1:(nlevels(ff)+1))-.5,
col=col[levels(ff)],
xaxt="n", yaxt="n"
)
axis(2, at=seq(0,1,length.out=nrow(dx)), labels=rev(paste("Task",dx$Tasks)), las=2)
axis(3, at=seq(0,1,length.out=length(names(dx))-1), labels=names(dx)[-1])
这将产生这样的画面。