Reputation: 322
I want heatmap squares blank (without color) on no significance by using ggplot2. Here are the codes which I have used for heatmap.
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()
Upvotes: 0
Views: 369
Reputation: 66415
You could filter the incoming data frame like this, though the specific result will depend on your cutoff choice:
ggplot(data=melted_cormat[melted_cormat$value != 1 & abs(melted_cormat$value) > 0.3,],
aes(Var2, Var1, fill=value))+
...
Upvotes: 2