library(corrplot)
## Warning: package 'corrplot' was built under R version 4.3.3
## corrplot 0.92 loaded
library(reshape)
## Warning: package 'reshape' was built under R version 4.3.3
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
head(mtcars)
##                    mpg cyl disp  hp drat    wt  qsec vs am gear carb
## Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
## Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
## Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
## Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
## Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
## Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1
m<-cor(mtcars)
head(m)
##             mpg        cyl       disp         hp       drat         wt
## mpg   1.0000000 -0.8521620 -0.8475514 -0.7761684  0.6811719 -0.8676594
## cyl  -0.8521620  1.0000000  0.9020329  0.8324475 -0.6999381  0.7824958
## disp -0.8475514  0.9020329  1.0000000  0.7909486 -0.7102139  0.8879799
## hp   -0.7761684  0.8324475  0.7909486  1.0000000 -0.4487591  0.6587479
## drat  0.6811719 -0.6999381 -0.7102139 -0.4487591  1.0000000 -0.7124406
## wt   -0.8676594  0.7824958  0.8879799  0.6587479 -0.7124406  1.0000000
##             qsec         vs         am       gear       carb
## mpg   0.41868403  0.6640389  0.5998324  0.4802848 -0.5509251
## cyl  -0.59124207 -0.8108118 -0.5226070 -0.4926866  0.5269883
## disp -0.43369788 -0.7104159 -0.5912270 -0.5555692  0.3949769
## hp   -0.70822339 -0.7230967 -0.2432043 -0.1257043  0.7498125
## drat  0.09120476  0.4402785  0.7127111  0.6996101 -0.0907898
## wt   -0.17471588 -0.5549157 -0.6924953 -0.5832870  0.4276059
corrplot(m, title = "Corrplot of mtcars 21MIC0065")

corrplot(m,method="pie", title = "Corrplot of mtcars using pie 21MIC0065")

corrplot(m,method="number", title = "Corrplot of mtcars using number 21MIC0065")

corrplot(m,type="upper",method="pie", title = "Corrplot of mtcars, type as upper and method as pie 21MIC0065")

corrplot(m,type="lower", method="number", title = "Corrplot of mtcars, type as lower and method as number - 21MIC0065")

corrplot(m, type="upper", col=c("black", "white"), bg="lightblue", diag=FALSE, title = "Corrplot of mtcars, type as upper - 21MIC0065")

corrplot.mixed(m, title = "Mixed corrplot of mtcars - 21MIC0065")

m1<-scale(mtcars)
head(m1)
##                          mpg        cyl        disp         hp       drat
## Mazda RX4          0.1508848 -0.1049878 -0.57061982 -0.5350928  0.5675137
## Mazda RX4 Wag      0.1508848 -0.1049878 -0.57061982 -0.5350928  0.5675137
## Datsun 710         0.4495434 -1.2248578 -0.99018209 -0.7830405  0.4739996
## Hornet 4 Drive     0.2172534 -0.1049878  0.22009369 -0.5350928 -0.9661175
## Hornet Sportabout -0.2307345  1.0148821  1.04308123  0.4129422 -0.8351978
## Valiant           -0.3302874 -0.1049878 -0.04616698 -0.6080186 -1.5646078
##                             wt       qsec         vs         am       gear
## Mazda RX4         -0.610399567 -0.7771651 -0.8680278  1.1899014  0.4235542
## Mazda RX4 Wag     -0.349785269 -0.4637808 -0.8680278  1.1899014  0.4235542
## Datsun 710        -0.917004624  0.4260068  1.1160357  1.1899014  0.4235542
## Hornet 4 Drive    -0.002299538  0.8904872  1.1160357 -0.8141431 -0.9318192
## Hornet Sportabout  0.227654255 -0.4637808 -0.8680278 -0.8141431 -0.9318192
## Valiant            0.248094592  1.3269868  1.1160357 -0.8141431 -0.9318192
##                         carb
## Mazda RX4          0.7352031
## Mazda RX4 Wag      0.7352031
## Datsun 710        -1.1221521
## Hornet 4 Drive    -1.1221521
## Hornet Sportabout -0.5030337
## Valiant           -1.1221521
heatmap(m1, scale="row", Colv=NA, Rowv=NA, xlab="attribute", ylab="car", main="Heatmap of mtcars - 21MIC0065")

heatmap(m1, xlab="attribute", ylab="car", main="Heatmap of mtcars with hcluster - 21MIC0065")

set.seed(8) 
m<-matrix(round(rnorm(200),2),10,10) 
## Warning in matrix(round(rnorm(200), 2), 10, 10): data length differs from size
## of matrix: [200 != 10 x 10]
colnames(m)<-paste("col",1:10) 
rownames(m)<-paste("row",1:10) 
head(m)
##       col 1 col 2 col 3 col 4 col 5 col 6 col 7 col 8 col 9 col 10
## row 1 -0.08 -0.76  1.28  1.51  0.36  1.08  0.56 -1.47  0.24   0.77
## row 2  0.84  0.29 -0.01  0.96 -0.61 -0.37  0.09  1.04 -0.79   1.57
## row 3 -0.46  0.42 -0.40 -1.55  0.23  0.59 -1.78  0.78 -1.09  -0.50
## row 4 -0.55 -1.29  0.02 -0.77 -0.26 -0.10 -1.11 -0.48  2.04  -0.62
## row 5  0.74  0.07  1.74  1.26  0.61  0.97 -0.27  0.09 -1.68  -1.35
## row 6 -0.11 -0.81 -1.11  0.43 -1.96  0.58 -1.08  0.60  1.22   0.77
df<-melt(m)
## Warning in type.convert.default(X[[i]], ...): 'as.is' should be specified by
## the caller; using TRUE
## Warning in type.convert.default(X[[i]], ...): 'as.is' should be specified by
## the caller; using TRUE
head(df)
##      X1    X2 value
## 1 row 1 col 1 -0.08
## 2 row 2 col 1  0.84
## 3 row 3 col 1 -0.46
## 4 row 4 col 1 -0.55
## 5 row 5 col 1  0.74
## 6 row 6 col 1 -0.11
colnames(df)<-c("x","y","value")

ggplot(df, aes(x=x, y=y, fill=value))+geom_tile()+labs(x = "ROWS", y = "COLUMNS", title = "Heatmap of Matrix - 21MIC0065")

ggplot(df,aes(x=x,y=y,fill=value))+geom_tile()+coord_fixed()+ labs(x = "rows", y = "columns", title = "Heatmap - 21MIC0065")

ggplot(df,aes(x=x,y=y,fill=value))+geom_tile(color="white",lwd=1.5,linetype=1)+coord_fixed()+geom_text(aes(label=round(value, 3)))+scale_fill_gradient(low="purple", high="orange")+labs(x = "rows", y = "columns", title = "Heatmap of Matrix with Color Gradient - 21MIC0065")