This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(pheatmap)
?pheatmap
# Create test matrix
test = matrix(rnorm(200), 20, 10)
test
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] -1.05028116 -0.80033491 -1.70049296 0.06139766 0.81286057 0.95726036
## [2,] 0.45532395 -0.09247468 1.44558652 1.57058913 1.20893747 0.73390628
## [3,] -2.96737084 -1.00695937 -1.74594441 -0.25939104 -0.09765317 -1.69196978
## [4,] 1.37941499 1.31065944 -0.93303685 2.16827107 -1.88600067 -1.65309942
## [5,] 0.74944968 0.04022907 -1.03701941 1.99834082 -1.14832777 0.41734242
## [6,] -0.48206538 0.52165160 -0.45570430 0.08298711 -0.29176485 0.99825947
## [7,] 1.09850791 0.01296574 -0.27888963 -0.51816584 0.87928123 1.70844565
## [8,] 1.40493491 -1.58848667 -0.85665501 -0.98339507 1.11301350 0.24249391
## [9,] 0.67821397 -0.06920382 -0.51622532 0.58465752 -0.04772259 -0.38947007
## [10,] -0.37713479 0.82780686 -1.92843165 0.08236750 0.47458860 -0.05585431
## [11,] 0.66390163 -0.61773405 -0.48503872 0.98661181 -0.95767266 0.79903895
## [12,] -0.22860563 1.15679007 1.37531221 0.52179943 -0.35795548 0.35713425
## [13,] -0.08132994 -0.47420034 -0.27554415 0.33223373 -1.15665229 0.37156242
## [14,] 1.41893443 0.31560888 0.83127562 1.51548545 0.47858455 -0.49135085
## [15,] 0.30189731 -0.98048257 -0.63825894 0.52854293 0.38569873 0.45855421
## [16,] -0.21605421 0.84743330 1.37993254 -0.32718158 1.97827766 0.86128096
## [17,] -0.81061104 0.13297154 -0.83770568 1.26237929 0.81260397 -0.49963301
## [18,] -0.15617321 -1.18711496 0.06776528 0.13403303 0.60858873 0.44554023
## [19,] 1.20863762 0.16236929 1.92523357 0.71046278 0.70586832 0.99858131
## [20,] 1.42272577 -0.06149075 0.24288162 0.27578524 1.04117762 0.16352310
## [,7] [,8] [,9] [,10]
## [1,] 1.0903505 -1.523938787 0.116808408 0.68360388
## [2,] -1.2760476 0.847887787 -1.472217315 -1.64745362
## [3,] -0.1864107 -0.007628738 -1.331083061 0.19541257
## [4,] -1.4872664 -0.563605345 -0.467591870 -1.79710150
## [5,] 1.0325777 1.287533065 0.203503696 -0.39443409
## [6,] 0.5951546 0.562888387 -1.487368891 0.97327597
## [7,] -1.3541318 -0.132582821 1.067920576 -1.69341072
## [8,] -0.7175910 -0.322690025 0.506424173 0.77938125
## [9,] -1.3076478 -0.836872799 1.454362862 1.03624709
## [10,] -0.3328218 0.225036777 0.445990187 -0.46823122
## [11,] -0.2358230 1.531243554 0.067705982 0.03338542
## [12,] -0.4016652 -1.280386847 0.005392328 1.10186997
## [13,] 1.6107183 -1.128253189 0.197336316 -0.56907039
## [14,] 0.5174615 -0.478703136 -0.071294926 0.41338431
## [15,] -0.6728647 1.415695809 -0.047513652 -0.97051506
## [16,] 0.4233057 -0.158191199 -0.449210959 1.12314489
## [17,] -1.0263541 -1.097940220 0.972804539 0.84207896
## [18,] 1.3926301 -0.781141095 -0.782699238 0.80905777
## [19,] 1.6266853 -0.414451692 -0.646880267 0.27342263
## [20,] -0.2551845 1.634229939 -0.742478214 1.50004079
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
test
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] 1.94971884 -0.80033491 1.29950704 0.06139766 3.8128606 0.95726036
## [2,] 3.45532395 -0.09247468 4.44558652 1.57058913 4.2089375 0.73390628
## [3,] 0.03262916 -1.00695937 1.25405559 -0.25939104 2.9023468 -1.69196978
## [4,] 4.37941499 1.31065944 2.06696315 2.16827107 1.1139993 -1.65309942
## [5,] 3.74944968 0.04022907 1.96298059 1.99834082 1.8516722 0.41734242
## [6,] 2.51793462 0.52165160 2.54429570 0.08298711 2.7082352 0.99825947
## [7,] 4.09850791 0.01296574 2.72111037 -0.51816584 3.8792812 1.70844565
## [8,] 4.40493491 -1.58848667 2.14334499 -0.98339507 4.1130135 0.24249391
## [9,] 3.67821397 -0.06920382 2.48377468 0.58465752 2.9522774 -0.38947007
## [10,] 2.62286521 0.82780686 1.07156835 0.08236750 3.4745886 -0.05585431
## [11,] 0.66390163 1.38226595 -0.48503872 2.98661181 -0.9576727 2.79903895
## [12,] -0.22860563 3.15679007 1.37531221 2.52179943 -0.3579555 2.35713425
## [13,] -0.08132994 1.52579966 -0.27554415 2.33223373 -1.1566523 2.37156242
## [14,] 1.41893443 2.31560888 0.83127562 3.51548545 0.4785846 1.50864915
## [15,] 0.30189731 5.01951743 -0.63825894 6.52854293 0.3856987 6.45855421
## [16,] -0.21605421 6.84743330 1.37993254 5.67281842 1.9782777 6.86128096
## [17,] -0.81061104 6.13297154 -0.83770568 7.26237929 0.8126040 5.50036699
## [18,] -0.15617321 4.81288504 0.06776528 6.13403303 0.6085887 6.44554023
## [19,] 1.20863762 6.16236929 1.92523357 6.71046278 0.7058683 6.99858131
## [20,] 1.42272577 5.93850925 0.24288162 6.27578524 1.0411776 6.16352310
## [,7] [,8] [,9] [,10]
## [1,] 4.0903505 -1.523938787 3.116808408 0.6836039
## [2,] 1.7239524 0.847887787 1.527782685 -1.6474536
## [3,] 2.8135893 -0.007628738 1.668916939 0.1954126
## [4,] 1.5127336 -0.563605345 2.532408130 -1.7971015
## [5,] 4.0325777 1.287533065 3.203503696 -0.3944341
## [6,] 3.5951546 0.562888387 1.512631109 0.9732760
## [7,] 1.6458682 -0.132582821 4.067920576 -1.6934107
## [8,] 2.2824090 -0.322690025 3.506424173 0.7793812
## [9,] 1.6923522 -0.836872799 4.454362862 1.0362471
## [10,] 2.6671782 0.225036777 3.445990187 -0.4682312
## [11,] -0.2358230 3.531243554 0.067705982 2.0333854
## [12,] -0.4016652 0.719613153 0.005392328 3.1018700
## [13,] 1.6107183 0.871746811 0.197336316 1.4309296
## [14,] 0.5174615 1.521296864 -0.071294926 2.4133843
## [15,] -0.6728647 7.415695809 -0.047513652 5.0294849
## [16,] 0.4233057 5.841808801 -0.449210959 7.1231449
## [17,] -1.0263541 4.902059780 0.972804539 6.8420790
## [18,] 1.3926301 5.218858905 -0.782699238 6.8090578
## [19,] 1.6266853 5.585548308 -0.646880267 6.2734226
## [20,] -0.2551845 7.634229939 -0.742478214 7.5000408
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")
pheatmap(test)
pheatmap(test, kmeans_k = 2)
pheatmap(test, scale = "row", clustering_distance_rows = "correlation")
pheatmap(test, color = colorRampPalette(c("navy", "white", "firebrick3"))(50))
pheatmap(test, cluster_row = FALSE)
pheatmap(test, legend = FALSE)
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.