Showing posts with label ggplot. Show all posts
Showing posts with label ggplot. Show all posts

28 June 2015

Plotting selangkah demi selangkah

Dear friends,

Long time no post LOL. Here's an update.

Finally!

I managed to translate an article by Hadley Wickham "Build a plot layer by layer" to Indonesian language for class purposes. I used R Markdown to write the article. But somehow, I can't get it uploaded to my Rpubs repo, as well as to this blogger site.

I've tried to implement a "(semi)-automating the R markdown to blogger workflow" described here, but did work.

So I rendered the Rmd to pdf and posted to my repos:

  1. Academia (pdf format) 
  2. ResearchGate (Rmd, R code)


I hope the translation is clear enough for anyone (especially Indonesian), who is starting to learn ggplot2 package.

Here's a plot from the original post.


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