# How can i plot a Correlation HeatMap?

**URL:** <https://discourse.julialang.org/t/how-can-i-plot-a-correlation-heatmap/78411>\
**Category:** General Usage\
**Tags:** question, plotting, plots, statsplots\
**Created:** [March 24, 2022, 4:01pm UTC](https://discourse.julialang.org/t/how-can-i-plot-a-correlation-heatmap/78411 "2022-03-24T16:01:13Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [March 24, 2022, 11:32pm UTC](https://discourse.julialang.org/t/how-can-i-plot-a-correlation-heatmap/78411/6 "2022-03-24T23:32:26Z")

</div>

Your efforts are commendable, but please note that this task should be less labor intensive. For example we could do:

```julia
using DataFrames, Statistics, Plots

# INPUT DATA
df = DataFrame(Age=rand(4), Balance=rand(4), Tenure=rand(4), Salary=rand(4))
cols = [:Age, :Balance, :Tenure] # define subset
M = cor(Matrix(df[!,cols])) # correlation matrix

# PLOT
(n,m) = size(M)
heatmap(M, fc=cgrad([:white,:dodgerblue4]), xticks=(1:m,cols), xrot=90, yticks=(1:m,cols), yflip=true)
annotate!([(j, i, text(round(M[i,j],digits=3), 8,"Computer Modern",:black)) for i in 1:n for j in 1:m])

```

(_ **NB** :_ added `yflip=true` _for standard orientation of matrix display)_

 ![Plots_heatmap_corr_matrix_annotated](https://global.discourse-cdn.com/julialang/original/3X/a/7/a77ef9eb6fa9f3df5609de8e92cb9a4a88d3d60d.png)

---

_[View the full topic](https://discourse.julialang.org/t/how-can-i-plot-a-correlation-heatmap/78411)._
