Develop a script in R to calculate and visualize a correlation matrix for a given dataset, with color-coded cells indicating the strength and direction of correlations, using ggplot2’s geom_tile function
library(ggplot2)library(tidyr)library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
# Use built-in mtcars datasetdata(mtcars)# Compute correlation matrixcor_matrix <-cor(mtcars)# Convert matrix to a data frame for plottingcor_df <-as.data.frame(as.table(cor_matrix))head(cor_df)