如何使用R为给定数据集绘制热图

如何使用R为给定数据集绘制热图,r,R,如何绘制Y轴ID为且X轴对应名称为的以下数据的热图 ID Name1 Name2 Name3 Name4 Name5 Name6 Gp2 2,86148 7,86926 5,00778 3,6586 5,66554 2,00694 Cldn10 3,30779 8,03876 4,73097 4,4237 7,96975 3,54605 Cld

如何绘制Y轴ID为且X轴对应名称为的以下数据的热图

  ID       Name1      Name2       Name3        Name4     Name5    Name6
  Gp2      2,86148    7,86926     5,00778      3,6586    5,66554  2,00694
 Cldn10    3,30779    8,03876     4,73097      4,4237    7,96975  3,54605
 Cldn10    4,261      8,7293      4,4683       4,3483    9,03017  4,68187
允许您指定数据包含标题和行名称:

x = read.table('filename', header = TRUE, row.names = 1)
heatmap(as.matrix(x))
这假设数据不包含“,”作为千位分隔符。如果要使用小数点,只需指定适当的选项:

x = read.table('filename', header = TRUE, row.names = 1, dec = ',')
如果输入数据包含逗号作为分隔符,则需要先删除它们:

raw_data = readLines('filename')
raw_data = gsub('(\\d+),(\\d+)', '\\1\\2', raw_data)
x = read.table(text = raw_data, header = TRUE, row.names = 1)

请向我们展示您的尝试,以便我们提供有针对性的帮助。仅使用默认的绘制热图的方法就可以直接处理数据。您以前尝试过吗?错误:“x”必须是数字matrix@beginner数字中还有逗号,是吗?是的,但实际上我需要小数。有没有办法去transform@beginner请参阅更新的答案。请注意,通过查看文档,这一点是显而易见的,在使用新功能时,您应该始终首先这样做。