以不同的颜色显示R散热图异常值 [英] Show R heatmap outliers in a different colour

查看:192
本文介绍了以不同的颜色显示R散热图异常值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望以不同颜色标记R矩阵中的异常值。
说我有数据

  1 2 4 2 5 
5 4 3 2 3
1 500 5 4 2

现在我要用不同的颜色标记500,剩下的有没有人可以指导我完成这个过程?

解决方案

这是一个体面的解决方法来实现这一点。使用 heatmap.2() gplots ,您可以在热图中为NA值指定任何颜色。所以,如果你使用一个简单的函数来代替源矩阵中的NAs,那么你可以用任何你喜欢的颜色代表它们。



首先,选择你的离群条件。例如,我们只要说大于10的任何值都是一个离群值。

 > m 
#[,1] [,2] [,3] [,4] [,5]
#[1,] 1 2 4 2 5
#[2,] 5 4 3 2 3
#[3,] 1 500 5 4 2

m [m> 10]< - NA

现在绘制热图。

  library(plots)
heatmap.2(m,trace =none,na.color =Green)



离群值现在很好,很明显。


Looking to mark outliers in R matrix in a different color. Say I have the data as

1  2  4  2  5
5  4  3  2  3
1 500 5  4  2

Now I want to mark the 500 with a different color and the remaining of the matrix with default color of the heatmap.

Can someone guide me through the process?

解决方案

Here's a decent workaround to achieve this. Using heatmap.2() from gplots, you can specify any colour for NA values in your heatmap. So, if you use a simple function to replace outliers with NAs in the source matrix, you can then represent them with any colour you like.

First, choose your outlier condition. For example's sake, let's just say that any value greater than 10 is an outlier.

> m
#      [,1] [,2] [,3] [,4] [,5]
# [1,]    1    2    4    2    5
# [2,]    5    4    3    2    3
# [3,]    1  500    5    4    2

m[m > 10] <- NA

Now plot the heatmap.

library(plots)
heatmap.2(m, trace = "none", na.color = "Green")

Outlier is now nice and obvious.

这篇关于以不同的颜色显示R散热图异常值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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