library(reshape2) #below are all the variable names
num_data=whi[, c("Score", "GDP per Capita", "Social support",
"Healthy life expectancy at birth",
"Freedom to make life choices", "Generosity",
"Perceptions of corruption",
"Headline Consumer Price Inflation")]
cor_matrix=round(cor(num_data, use = "complete.obs"), 2)
melted=melt(cor_matrix)
ggplot(melted,aes(Var1, Var2, fill = value)) +
geom_tile(color="white")+
scale_fill_gradient2(low="#d73027",high="#1a9850", #range
mid="white",midpoint=0,limit=c(-1, 1)) +
labs(title = "Correlations of Happiness and Life Factors",
x = "", y = "", fill = "Correlation") + #titles and axes
theme_minimal(base_size = 14) +
theme(axis.text.x=element_text(angle = 45, hjust = 1, size = 10),
axis.text.y=element_text(size=10)) #adjusting squares