如何在数据帧上多次制作二进制热图 [英] how to make a binary heat map several times on a data frame

查看:43
本文介绍了如何在数据帧上多次制作二进制热图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下所示的数据

I have a data looks like below

df<- structure(list(time = c(1L, 1L, 1L, 1L, 1L, 
1L, 5L, 5L, 5L, 5L, 5L, 5L, 12L, 12L, 12L, 12L, 12L, 12L
), grp = c("A", "B", "C", "D", "E", "F", "A","B", "C", "D", "E", 
"F", "A", "B", "C", "D", "E", "F"), `02` = c(36034L, 63763L, 
51432L, 65100L, 61444L, 71012L, 266610L, 389787L, 47659L, 63156L, 
84593L, 84331L, 514204L, 685995L, 325569L, 394893L, 88586L, 119206L
), `03` = c(45632L, 66505L, 60360L, 36685L, 107551L, 53360L, 
323952L, 344944L, 69601L, 51268L, 130665L, 59704L, 541017L, 578627L, 
424918L, 336442L, 156380L, 80952L), `04` = c(59025L, 52837L, 
68571L, 35788L, 75262L, 66601L, 424683L, 340948L, 79487L, 42809L, 
95607L, 81739L, 729858L, 606794L, 501805L, 333508L, 112263L, 
112676L), `05` = c(74767L, 48210L, 70972L, 67705L, 85576L, 89265L, 
393380L, 306633L, 77816L, 73611L, 106317L, 116890L, 677483L, 
533762L, 375046L, 483442L, 136605L, 160272L), `06` = c(50846L, 
37970L, 63896L, 78296L, 81216L, 62308L, 62613L, 21770L, 80955L, 
88832L, 97586L, 68345L, 100610L, 38642L, 130879L, 134422L, 164913L, 
112949L), `07` = c(26688L, 27830L, 17010L, 54074L, 26727L, 31109L, 
24448L, 38701L, 17378L, 46327L, 25324L, 25325L, 22457L, 33676L, 
20154L, 33916L, 25483L, 24284L), `08` = c(16498L, 26604L, 41201L, 
38417L, 43709L, 33217L, 69943L, 80638L, 37444L, 31701L, 46781L, 
31152L, 69223L, 102067L, 47771L, 70210L, 44783L, 22790L), `09` = c(16272L, 
24485L, 14546L, 74756L, 28193L, 770L, 72238L, 78418L, 9161L, 
48618L, 26466L, 1078L, 67369L, 89824L, 37838L, 93295L, 20890L, 
998L), `10` = c(20612L, 713L, 18114L, 57872L, 25684L, 27985L, 
73618L, 1770L, 11953L, 33347L, 25824L, 25860L, 70949L, 1520L, 
46044L, 66312L, 20971L, 20217L), `11` = c(23549L, 856L, 32854L, 
42906L, 33385L, 26218L, 88509L, 62103L, 23377L, 29738L, 33504L, 
26642L, 104893L, 100707L, 53324L, 63296L, 24867L, 21114L)), .Names = c("time", 
"grp", "02", "03", "04", "05", "06", "07", "08", "09", "10", 
"11"), class = "data.frame", row.names = c(NA, 18L))

我想对这些数据制作 3 次二进制热图.

I want to make a binary heatmap 3 times on this data.

时间1有A到F,时间5有A到F,时间12有A到F

There are A to F at time 1, A to F at time 5 and A to F at time 12

我想获得每个时间集的最小和最高之间的范围,然后进行类似这样的二元着色

I want to get the range between the smallest and the highest for each time set and then make a binary coloring something like this

推荐答案

我不确定您希望您的情节是什么样的 - 在我看来,您同时拥有 grp 和各种数字(参与者 ID?) 作为潜在的 x 轴变量.y轴是平均值吗?

I'm not exactly sure what you want your plot to look like - it seems to me that you have both the grp and the various numbers (participant IDs?) as potential x-axis variables. And are the y-axis marks the mean value?

无论如何,我已经为您的绘图设置了一些数据:

Regardless, I've got your data set up a bit for plotting:

require(ggplot2)
require(reshape2)
test <- melt(df, id = c("time", "grp"), variable.name = "Participant", 
                                        value.name = "Score")

test2 <- spread(test, key = time, value = Score)
colnames(test2) <- c("Group", "Participant", "T1", "T5", "T12")

此时,您可以执行以下操作:

From this point, you can do something like:

ggplot(test2) + geom_tile(aes(x = Group, y = Participant, fill = T1))

这不完全是您想要的,但我对您的情节中发生的事情感到有些困惑.至少可以让您开始制作热图

It's not exactly what you want, but I'm a little confused about what is going where on your plot. That'll get you started on heatmapping, at least

这篇关于如何在数据帧上多次制作二进制热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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