How can I make this correlation plot?

how can I make a plot like this in Julia? Which package should i use? I have used corrplot but I don’t think we can get plot like this with that.

Isn’t that just a heatmap with a bunch of annotations? Shouldn’t be very hard in any plotting package?

1 Like

Ok I will try that :).

A follow up what about this plot with base function? with correlation coefficient.

That’s basically corrplot from StatsPlots though isn’t it?


If you want to exactly reproduce some R plot, you can also just RCall ggplot2 (or whatever you’re using in R). Alternatively you’ll have to get comfortable with the details of composing plots in your favourite plotting library (e.g. your last plot looks like three density plots, three scatter plots and three emtpy plots with just annotate in Plots.jl, but getting the legends to look exactly like you have there as grey boxes might be a bit of effort and potentially easier in Makie)

1 Like

In corrplot is there any option to remove right side plots and rather get corr values ?

Not that I know of, but look at the docs. As I said if you want a plot to exactly look a specific way you should just build it, it’s pretty simple to stitch together from the basics and you can customise things to your heart’s content.

1 Like

Hi, I think you are looking for this: How can i plot a Correlation HeatMap? - #6 by rafael.guerra Cheers

1 Like

Yeah I found that after sometime :sweat_smile:. Thanks!

1 Like

when i’m saving my plot, I’m getting blur image for right side plots. Also I had question what exactly right side represent?

image

People have replied to quite a few of your threads already that asking for help without any runnable code is hard, but for completeness please read

And follow those best practices when posting.

I did that plot sometime ago with Plots and DataFrames and corr, I wrote an small article here World Happiness Report - EDA & clustering with Julia - Julia Community 🟣

You can use a function like this:

function heatmap_cor(df)
    cm = cor(Matrix(df))
    cols = Symbol.(names(df))

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

In that exercise the result was as follow:

7 Likes

This sort of thing is called a scatter-plot matrix, corner plot, or pair plot. There is a Julia package called PairPlots.jl that does this for you, except for the correlation values. But you could presumably add those pretty easily using Makie’s text function.

1 Like

Others have looked for this as well. This takes a few lines of code to implement yourself. Have a look at How can i plot a Correlation HeatMap? - #8 by fabern, that shows solutions with Plots.jl or Makie.jl.