R 如何在无显著系数的情况下将热图方块留空?
我想热图方块空白(没有颜色)的意义上没有使用ggplot2。这是我用来制作热图的代码R 如何在无显著系数的情况下将热图方块留空?,r,ggplot2,R,Ggplot2,我想热图方块空白(没有颜色)的意义上没有使用ggplot2。这是我用来制作热图的代码 data(mtcars) cormat <- round(cor(mtcars), 2) # Get upper triangle of the correlation matrix get_upper_tri <- function(cormat){ cormat[lower.tri(cormat)]<- NA return(cormat) } upper_tri <- g
data(mtcars)
cormat <- round(cor(mtcars), 2)
# Get upper triangle of the correlation matrix
get_upper_tri <- function(cormat){
cormat[lower.tri(cormat)]<- NA
return(cormat)
}
upper_tri <- get_upper_tri(cormat)
# Finished correlation matrix heatmap
library(reshape2)
melted_cormat <- melt(upper_tri,
na.rm=TRUE) # Melt the correlation matrix
# Heatmap
library(ggplot2)
ggplot(data=melted_cormat, aes(Var2, Var1, fill=value))+
geom_tile(color="white")+
scale_fill_gradient2(low="blue", high="red", mid="white",
midpoint=0, limit=c(-1,1), space="Lab",
name="Pearson\nCorrelation")+
ggtitle("Title")+
xlab("V1")+
ylab("V2")+
theme_minimal()+
theme(axis.text.x=element_text(angle=90, vjust=0.5,
size=10, hjust=1))+
coord_fixed()
数据(mtcars)
cormat您可以像这样过滤传入的数据帧,尽管具体结果取决于您的截止选择:
ggplot(data=melted_cormat[melted_cormat$value != 1 & abs(melted_cormat$value) > 0.3,],
aes(Var2, Var1, fill=value))+
...
谢谢你,如果我想知道0.95的有效水平,我可以了解过滤器使用“abs(融化的cormat$value)>0.3”的情况吗。