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())
Best wishes
Alex