简体   繁体   中英

R correlation heatmap: showing only values in the threshold

Here is the code (library: corrplot):

df <- read.table(header=T, text="v1 v2 v3 v4 
1          1         5          3         2  
2          2         4          4         5  
3          3         3          5         1  
4          4         2          1         3  
5          5         1          2         4  
") 
cormat<-cor(df)
corrplot(cormat)

I would like to show in the heatmap ONLY the dots for the correlation coefficients between -0.2 and +0.2 (all others I would like to be just empty white squares). Could somebody help please?

Just set the unwanted values to zero:

tmp = cormat # Copy matrix
tmp[ tmp < -0.2 | tmp > 0.2 ] = 0
corrplot(tmp)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM