Correlation Heatmap

General help and assistance with jamovi. Bug reports can be made at our issues page: https://github.com/jamovi/jamovi/issues . (If you're unsure feel free to discuss it here)
Post Reply
alex99
Posts: 6
Joined: Wed Sep 20, 2023 12:58 pm

Correlation Heatmap

Post by alex99 »

Hi there,

I wanted to get a correlation heatmap of 18 items but when I check the "heatmap" box (in the analysis "correlation matrix"), the heatmap looks very messy because the numbers overlap. I saw a similar post from a while ago where the tip was to use shorter names for the variables but I tried that and nothing changed. So then I tried to compute a heatmap with the Rj editor + and even limited the decimal places to one but it actually looks worse. I was wondering if / how I could program the heatmap in the Rj editor + to be wider so that it has more space for each square but since I'm not very experienced with R (or any programming language, really), I don't know how the code would have to look like. Now, I was using this:

Code: Select all

library(reshape2)
library(ggplot2)

#create data frame
df <- data

#calculate correlation between each pairwise combination of variables
cor_df <- round(cor(df), 1)

#melt the data frame
melted_cormat <- melt(cor_df)

#create correlation heatmap
ggplot(data = melted_cormat, aes(x=Var1, y=Var2, fill=value)) + 
  geom_tile() +
  geom_text(aes(Var2, Var1, label = value), size = 5) +
  scale_fill_gradient2(low = "red", high = "green",
                       limit = c(-1,1), name="Correlation") +
  theme(axis.title.x = element_blank(),
        axis.title.y = element_blank(),
        panel.background = element_blank())
I'd be very happy if anyone has an idea how to solve this!
Best wishes
Alex
Post Reply