@@ -8,7 +8,7 @@ library(RColorBrewer)
8
8
data <- read.csv(" dataset.csv" , comment.char = " #" )
9
9
rnames <- data [,1 ] # assign labels in column 1 to "rnames"
10
10
mat_data <- data.matrix(data [,2 : ncol(data )]) # transform column 2-5 into a matrix
11
- rownames(mat_data ) <- rnames # assign row names
11
+ rownames(mat_data ) <- rnames # assign row names
12
12
13
13
14
14
@@ -20,27 +20,44 @@ rownames(mat_data) <- rnames # assign row names
20
20
my_palette <- colorRampPalette(c(" red" , " yellow" , " green" ))(n = 299 )
21
21
22
22
# (optional) defines the color breaks manually for a "skewed" color transition
23
- col_breaks = c(seq(- 1 ,0 ,length = 100 ), # for red
24
- seq(0 ,0.7 ,length = 100 ), # for yellow
25
- seq(0.7 ,1 ,length = 100 )) # for green
23
+ col_breaks = c(seq(- 1 ,0 ,length = 100 ), # for red
24
+ seq(0.01 ,0.7 ,length = 100 ), # for yellow
25
+ seq(0.71 ,1 ,length = 100 )) # for green
26
26
27
27
# creates a 5 x 5 inch image
28
- png(" h1_simple.png" ,
28
+ png(" h1_simple.png" ,
29
29
width = 5 * 300 , # 5 x 300 pixels
30
30
height = 5 * 300 ,
31
31
res = 300 , # 300 pixels per inch
32
32
pointsize = 8 ) # smaller font size
33
33
34
- heatmap.2(mat_data ,
34
+ heatmap.2(mat_data ,
35
35
cellnote = mat_data , # same data set for cell labels
36
36
main = " Correlation" , # heat map title
37
37
notecol = " black" , # change font color of cell labels to black
38
38
density.info = " none" , # turns off density plot inside color legend
39
39
trace = " none" , # turns off trace lines inside the heat map
40
40
margins = c(12 ,9 ), # widens margins around plot
41
- col = my_palette , # use on color palette defined earlier
41
+ col = my_palette , # use on color palette defined earlier
42
42
breaks = col_breaks , # enable color transition at specified limits
43
43
dendrogram = " row" , # only draw a row dendrogram
44
44
Colv = " NA" ) # turn off column clustering
45
45
46
+ # #############################################################################
47
+ # NOTE
48
+ # #############################################################################
49
+ # The color breaks above will yield a warning
50
+ # "...unsorted 'breaks' will be sorted before use" since they contain
51
+ # (due to the negative numbers). To avoid this warning, you can change the
52
+ # manual breaks to:
53
+ #
54
+ # col_breaks = c(seq(0,1,length=100), # for red
55
+ # seq(1.01,1.7,length=100), # for yellow
56
+ # seq(1.71,2,length=100)) # for green
57
+ #
58
+ # However, the problem is then that our heatmap contains negative values
59
+ # which will then not be colored correctly. Remember that you don't need to
60
+ # provide manual color breaks at all, this is entirely optional.
61
+ # #############################################################################
62
+
46
63
dev.off()
0 commit comments