23 February 2015

Heatmap and corrgram to evaluate student's scores (updated)

Dear friends,
Here's my try out of making heatmap and corrgram in R to evaluate student performance. Both plots can be used to evaluate your students' performance and clustering. The number on the right side contains the student's number, and the tree on the left shows the clustering. Figure left (heatmap), Figure right (correlation matrix). The following is the code:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#install.packages("corrgram")
library(corrgram)
library(ggplot2)
# Using mtcars data
corrgram(mtcars)
heatmap(as.matrix(mtcars))
head(mtcars)
pairs(mtcars, main = "mtcars data")
coplot(mpg ~ disp | as.factor(cyl), data = mtcars,
       panel = panel.smooth, rows = 1)
# Some tweaking
library(RColorBrewer)
x  <- as.matrix(mtcars)
rc <- rainbow(nrow(x), start = 0, end = .3)
cc <- rainbow(ncol(x), start = 0, end = .3)
heatmap(x, Rowv=NA, Colv=NA, col=brewer.pal(9, "Blues")[1:9], scale="none", 
        margins=c(5,10), revC=T)
##############################################################
# Using scores data
# loading data (you can use any numerical data)
Scores <- read.csv("Scores.csv", header=T) 
# view data frame's dimension, headers, etc
View(Scores)
dim(Scores)
str(Scores)
# subsetting data frame
Scores2 <- Scores[c(2:11)] 
# making correlation matrix and heatmap
corrgram(Scores2)
heatmap(as.matrix(Scores2))

Results:
from 'corrgram(mtcars)'
from 'coplot(mpg .... etc)'
from 'corrgram(Scores2)'
from 'heatmap(as.matrix(Scores2))'

Happy heating :-) Thanks for stopping by.

@dasaptaerwin






Post a Comment