I have a matrix that I already cut into the upper triangle:
eSim <- c(1,1,-1,-1,1,1,-1,-1,-1,-1,1,1,-1,-1,1,1)
dim(eSim) <- c(4,4)
rownames(eSim)=c("PosLong\n1200", "PosLong\n1800", "Neglong\n1200", "Neglong\n1800")
colnames(eSim)=c("PosLong\n1200", "PosLong\n1800", "Neglong\n1200", "Neglong\n1800")
# Get upper triangle of the correlation matrix
get_upper_tri <- function(cormat){
cormat[lower.tri(cormat)]<- NA
return(cormat)
}
eSim_upper <- get_upper_tri(eSim)
melted_eSim_upper <- melt(eSim_upper, na.rm = TRUE)
And this is my code for plotting this matrix
ggplot(data = melted_eSim_upper, aes(Var2, Var1, fill = as.factor(value)))+
geom_tile(color = "black", size=0.8)+
scale_fill_manual(values=c("#8DD3C7", "#FB8072"))+
theme_minimal()+
theme(axis.text.x = element_text(angle = 45, vjust = 1,
size = 12, hjust = 1))+
theme(axis.text.y = element_text(angle = 45, vjust = 1,
size = 12, hjust = 1))+
coord_fixed()+
theme(axis.title.x = element_blank(),
axis.title.y = element_blank())+
theme(panel.background = element_blank(),
panel.grid.major = element_blank(),
panel.border = element_blank())+
theme(axis.text.y = element_text(margin = margin(t = 0, r = 0, b = 0, l = 50)))
The outcome:
I have several questions to acheive my final goal:


