类似热图的绘图,但对于分类变量 [英] heatmap-like plot, but for categorical variables

查看:447
本文介绍了类似热图的绘图,但对于分类变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于大约50个人,我有三个因素(set1,set2和set3)。 set1,set2和set3的值是A,B,C。我想制作这些数据的散热图样图,但​​图例显示了与值相关的颜色(例如,A ='红色',B ='蓝色',C ='黑色')。任何建议?



谢谢。

解决方案

easig用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),
color =white)+ scale_fill_manual(values = c(red,blue,black))


I have three factors (set1, set2, and set3) for each of about 50 individuals. The values for set1, set2, and set3 are "A","B","C". I'd like to make a heatmap-like plot of these data but have the legend show the color associated with the values (eg., A='red', B='blue', C='black'). Any suggestions?

Thanks.

解决方案

I decided it would be easist to approach this with ggplot2 (for me anyway):

#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"))

这篇关于类似热图的绘图,但对于分类变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆