geom_tile() draws the rectangular cells of a ggplot2 heat map. Map two variables to x and y, then map a value such as a correlation coefficient to fill. section 2.5.4
For a correlation matrix, reshape the computed coefficients into Var1, Var2, and value columns. Each row then supplies one tile and its color. section 2.5.4
Correlation heat map
p4 <- ggplot(data = draft_cor, aes(x = Var1, y = Var2, fill = value)) + geom_tile() + scale_fill_gradient2(midpoint = 0.5, mid = "grey84", limits = c(-1, 1)) + geom_text(aes(label = round(value, 2)), color = "black", fontface = "bold", size = 5) The resulting matrix uses color gradients for positive and negative associations and labels each tile with its rounded coefficient.
