here is the dataset I am working on, from the link: https://worldhappiness.report/ed/2022/ file name: Data_for_Figure_2.1
I am trying to find how the variables correlate in a correlation map, the code was written as below
corr <- cor(happy22[, 3:8], method = "pearson")
ggplot(melt(corr, varnames = c("x", "y"), value.name = "correlation"),
aes(x = x, y = y)) +
geom_tile(aes(fill = correlation)) +
scale_fill_gradient2(
low = "green",
mid = "yellow",
high = "red",
guide = guide_colorbar(ticks = FALSE, barheight = 5),
limits = c(-1, 1)
) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
labs(title = "Heatmap of correlation matrix",
x = NULL, y = NULL)
the error shows:
Error in FUN(X[[i]], ...) : object 'correlation' not found
In addition: Warning messages:
1: In type.convert.default(X[[i]], ...) :
'as.is' should be specified by the caller; using TRUE
2: In type.convert.default(X[[i]], ...) :
'as.is' should be specified by the caller; using TRUE
I cant figure out what this means, why 'correlation' not found? where is 'as.is' in my code?
Could anyone please help?
